Description
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.
InputThe input file contains any number of lines, and each one consisting of a number for the amount of money in cents.
OutputFor 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
The main idea: give you n dollars, let you divide into 1.5.10.25.50 change, ask how many ways, memory search
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intdp[7500][5];intv[5] = {1,5,Ten, -, -};intDP (intIintj) { if(J = =0) returnDP[I][J] =1; if(Dp[i][j]! =-1) returnDp[i][j]; DP[I][J]=0; for(intK =0; I-k*v[j] >=0; k++) Dp[i][j]+ = DP (i-k*v[j],j-1); returndp[i][j];}intMain () {memset (DP,-1,sizeof(DP)); intN; while(~SCANF ("%d",&N)) { for(inti =0; I <= N; i++) dp[i][0] =1; printf ("%d\n", DP (N,4)); } return 0;}
View Code
If the above is not going to make dp[i][j] clear to 0
Uva674--dp--coin Change