在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
Input
每行只有一个正整数N,N小于32768。
Output
对应每个输入,输出兑换方法数。
Sample Input
2934
12553
Sample Output
718831
13137761
简单dp,代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef unsigned long long ll;
const int MAXN=4e4;
ll dp[MAXN];
int main(){
int n;
while(~scanf("%d",&n)){
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=3;i++){
for(int j=1;j<=n;j++){
dp[j]+=dp[j-i];
}
}
printf("%lld\n",dp[n]);
}
return 0;
}