首先题目读的费劲!另外不能在for循环中定义变量i,j之类的,否则会超时!!!
dp[i][j] += dp[i-1][j-k], i >= 2,j <= 9*i && k < j && k <= 9;
#include <iostream>
#include <cstring>
#include <cstdio>using namespace std;const int MAXN = 82;int dp[10][MAXN];//dp[i][j]前i位之和等于j的数目void Pre()
{int i, j, k;memset(dp, 0, sizeof(dp));for(i = 1; i <= 9; ++i)//不能再for循环中定义变量i,否则会超时!!!!dp[1][i] = 1;for(i = 2; i <= 9; ++i){for(j = 1; j <= 9*i; ++j){for(k = 0; k < j && k <= 9; ++k)dp[i][j] += dp[i-1][j-k];//dp[i-1][j-k]表示总会有一个且仅有一个m(m >= 0 && m <= 9),使得dp[i-1][j-k] + m = dp[i][j],其中dp[i-1][j-k]表示前i-1位之和为j-k}}
}int main()
{int n;int i;Pre();while(~scanf("%d", &n)){if(n == 1){printf("10\n");continue ;}int ans = 0;for(i = 1; i <= 9; ++i)ans += dp[i][n];printf("%d\n", ans);}return 0;
}