DP(6)

Milliard Vasya's Function

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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 = 10 9) because Vasya himself won’t cope with the task. Can you solve the problem?

Input

Integer S (1 ≤ S ≤ 81).

Output

The milliard VF value in the point S.

Sample Input

inputoutput
1
10
 
#include<cstdio>
using namespace std;
int dp[10][100];
int main(){
    dp[0][0] = 1;
    for(int i = 1; i <= 9; i++)//位数;
        for(int j = 0; j <= 81; j++)//j = sum(i-1);
            if(dp[i-1][j])//判断sum(i-1)是否存在;
                for(int k = 0; k <= 9; k++)//num(i) = {0~9};
                    dp[i][j+k] += dp[i-1][j];//若存在,sum(i) = num(i) + sum(i-1);
    int n;
    scanf("%d",&n);
    int ans = dp[9][n];
    if(n==1)ans++;//if(N == 1e9)sum(10) = 1;
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2015-08-28 09:44  Tobu  阅读(116)  评论(0)    收藏  举报