题目看不懂,,,
简直了
其实开始都是废话,重要的就一句
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.
就是求1到N中各位数字之和为S的数的个数
只想看题意的童鞋现在可以ctrl+w了
---------------下面是思路的分界线-------------
就是一个简单的dp
可以由N的位数来划分状态
以下是状态转移方程
dp[i][j]+=dp[i-k][j-1];
其中j是N的位数,i是N的各位数之和,k的取值是0~9
dp[s][9]即为所求
(好像没什么好说的了。。还是直接上代码吧
(哦对了,题中给的N是10^9 所以dp[1][9]要+1 (想一想,为什么
#include<cstdio>
#include<cstring>
using namespace std;
int dp[100][11];
int main(){
int s;
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int j=1;j<=9;j++)
for(int k=0;k<=9;k++)
for(int i=k;i<=81;i++)
dp[i][j]+=dp[i-k][j-1];
dp[1][9]++;
while(~scanf("%d",&s)){
printf("%d\n",dp[s][9]);
}
return 0;
}