Coin Change
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Suppose there is 5 types of coins:50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we had one cents, then we can make changes with one 10-cent coin and one 1-cent coin, one 5-cent coins and One 1-cent coin, one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there is four ways of making changes for one cents with the above coins. Note that we count this there is one of the making change for zero cent.
Write a program to find the total number of different ways of making changes for all amount of money in cents. Your program should is able to handle up to 7489 cents.
Input
The input file contains any number of lines, and each one consisting of a number for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of COI Ns.
Sample Input
1126
Sample Output
413
Test instructions: There are 1,5,10,25,50 five kinds of coins, give a number, ask a few ways of pooling to make up this number.
Analysis: Classic DP problem ... can be recursive or memory search ... This problem test instructions and HDU2069 exactly the same, but the same code is not submitted, often time out, or see the idea of the great God to turn.
1#include <cstdio>2#include <cstring>3 Const intMAXN =8000;4 Const intcoin[5] = {1,5,Ten, -, -};5 intN;6 Long Longdp[maxn][5];7 8 Long LongSolveintIints)9 {Ten if(Dp[s][i]!=-1) One returnDp[s][i]; Adp[s][i]=0; - for(intj=i;j<5&& s>=coin[j];j++) -Dp[s][i]+=solve (j,s-coin[j]); the returnDp[s][i]; - } - - intMain () + { -memset (dp,-1,sizeof(DP)); + for(intI=0;i<5; i++) Adp[0][i]=1; at while(~SCANF ("%d",&N)) -printf"%lld\n", Solve (0, N)); - return 0; -}
UVa 674 Coin Change (classic DP)