Description
Vasya is the beginning mathematician. He decided to make a important contribution to the science and to become famous all over the world. But what can he do and if the most interesting facts such as Pythagor ' s theorem is 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) is rather simple:the value of the
NTh VF in the point
Sis a amount of integers from 1 to
NThat has the sum of digits
S. You seem to is great programmers, so Vasya gave a task to find the milliard VF value (i.e. the VF with
N= 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
S.
Sample Input
The main idea: ask you from 1 to 10^9 the number of all bits added to S is how many of us define DP[I][J] to represent the sum of the number of I bits and for J, then you can get the state transfer equation dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + ... dp[i-1][ J-9] Of course meet j-9 >= 0 because consider is the current state and the original state of the change, the state as a whole, to insert just an element, dp[i-1][j] means to enter 0, the other means to insert K, consider when s = 1 o'clock, to add 1
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int dp[10][85];int Main ( ) { int S; Memset (Dp,0,sizeof (DP)); for (int i = 1; I <= 9; i++) dp[1][i] = 1; for (int i = 2, I <= 9; i++) {for (int j = 1; J <= Bayi; j + +) { dp[i][j] = dp[i-1][j]; for (int k = 1; k <= 9 && k <= J; k++) { Dp[i][j] + = dp[i-1][j-k] ; }} while (~SCANF ("%d", &s)) { int ans = 0; if (S = = 1) {printf ("10\n"); continue;} for (int i = 1; I <= 9;i++) ans + = dp[i][s]; printf ("%d\n", ans); } return 0;}
Ural1353--dp--milliard Vasya ' s Function