Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
Input
每行只有一个正整数N,N小于32768。
Output
对应每个输入,输出兑换方法数。
Sample Input
2934
12553
Sample Output
718831
13137761
/**
审题达意:
有货币n,可以用1,2,3钱币兑换,求有多少种分法
个人理解:
完全背包问题
错误点:
dp[i] = dp[i-1] + dp[i-2] + dp[i-3] //会各自包含,重复了
*/
#include <stdio.h>
#include <string.h>
#define mLen 32769
int dp[mLen];
int main()
{
int n;
scanf("%d",&n);
memset(dp,0,sizeof(dp));
dp[0] = 1;
for(int i=1;i<=3;i++)
{
for(int j=i;j<=n;j++)
{
dp[j] += dp[j-i];
}
}
printf("%d\n",dp[n]);
return 0;
}