Topic Portal
1 /*2 Test instructions: The number of digits in 1~1e9, the number of each digit number added and the number of S3 Recursive dp:dp[i][j] represents the I-digit number, the current number and the number of J4 State transfer equation: dp[i][j] + = Dp[i-1][j-k], in order not to show negative numbers5 instead: dp[i][j+k] + = Dp[i-1][j]6 */7#include <cstdio>8#include <cstring>9#include <cmath>Ten#include <algorithm> One#include <string> A using namespacestd; - - Const intMAXN = 1e4 +Ten; the Const intINF =0x3f3f3f3f; - intdp[Ten][ -]; - - intMainvoid)//URAL 1353 milliard Vasya ' s Function + { - //freopen ("f.in", "R", stdin); + A ints; at while(SCANF ("%d", &s) = =1) - { -Memset (DP,0,sizeof(DP)); - -dp[0][0] =1; - for(intI=1; i<=9; ++i) in { - for(intj=0; j<=s; ++j) to { + if(dp[i-1][j]) - { the for(intk=0; k<=9; ++K) dp[i][j+k] + = dp[i-1][j]; * } $ Panax Notoginseng } - } the + if(s = =1) dp[9][s] + =1; Aprintf ("%d\n", dp[9][s]); the } + - return 0; $}
Recursive DP URAL 1353 milliard Vasya ' s Function