VF

VF

描述

Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythagor’s theorem are already proved? Correct! He is to think out something his own, original. So he thought out the Theory of Vasya’s Functions. Vasya’s Functions (VF) are rather simple: the value of the Nth VF in the point S is an amount of integers from 1 to N that have the sum of digits S. You seem to be great programmers, so Vasya gave you a task to find the milliard VF value (i.e. the VF with N = 109) because Vasya himself won’t cope with the task. Can you solve the problem?

输入There are multiple test cases. Integer S (1 ≤ S ≤ 81).输出The milliard VF value in the point S.样例输入

1

样例输出

10
 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <memory.h>
#include <string>
#include <math.h>
using namespace std;
  int arr[9][81];
int main()
{
      int n;
              for(int i=1;i<=9;i++)
            arr[1][i] = 1;

        for(int i=1;i<=9;i++)
            for(int j=1;j<=9*i;j++)
                for(int k=0;k<=9 && k<=j;k++)
                    arr[i][j] += arr[i-1][j-k];

         while(cin>>n)
      {
          if(n==1)
          {
              cout<<10<<endl;
              continue;
          }


        int sum = 0;
        for(int i=1;i<=9;i++)
            sum += arr[i][n];
        cout<<sum<<endl;
      }
     return 0;
}

            

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏算法修养

HDU 5877 2016大连网络赛 Weak Pair(树状数组,线段树,动态开点,启发式合并,可持久化线段树)

Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144...

40210
来自专栏杨熹的专栏

【LEETCODE】模拟面试-134-Gas Station

新生 题目: https://leetcode.com/problems/gas-station/ There are N gas stations alon...

3536
来自专栏Urahara Blog

Web For Pentester - SQLi Part Tips

1961
来自专栏Java成神之路

Java_数据交换_JAXB_用法入门

JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术。该过程...

1143
来自专栏wym

Educational Codeforces Round 44 (Rated for Div. 2)A. Chess Placing

You are given a chessboard of size 1 × n. It is guaranteed that n is even. The c...

1282
来自专栏java、Spring、技术分享

深入分析Spring MVC中RequestBody与ResponseBody

  在SpringMVC中,可以使用@RequestBody和@ResponseBody两个注解,分别完成请求报文到对象和对象到响应报文的转换。在Sprin...

2791
来自专栏码匠的流水账

聊聊storm的GraphiteStormReporter

storm-core-1.2.2-sources.jar!/org/apache/storm/metrics2/reporters/GraphiteStormR...

1441
来自专栏小樱的经验随笔

Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】

D. Time to go back time limit per test:1 second memory limit per test:256 megaby...

2966
来自专栏ml

HDUOJ----(1030)Delta-wave

Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K...

3497
来自专栏向前进

【笔记】实现一个简易的Promise

const PENDING_STATE = "pending"; const FULLFILL_STATE = "fullfilled"; const REJE...

3314

扫码关注云+社区

领取腾讯云代金券