Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
Input
每行只有一个正整数N,N小于32768。
Output
对应每个输入,输出兑换方法数。
Sample Input
2934
12553
Sample Output
718831
13137761
Author
SmallBeer(CML)
Source
杭电ACM集训队训练赛(VII)
Recommend
lcy
代码
#include <cstdio>
#include <cstring>
using namespace std;
const int coinValue[10] = {0, 1, 2, 3};
int dp[40000];
int coinProblem(int value){
int iA, jA;
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for(iA = 1; iA <= 3; iA++){
for(jA = coinValue[iA]; jA <= value; jA++) dp[jA] += dp[jA - coinValue[iA]];
}
return dp[value];
}
int main(){
int moneyValue;
while(~scanf("%d", &moneyValue)) printf("%d\n", coinProblem(moneyValue));
return 0;
}