This is a complete backpack problem. The number of coins in the question cannot exceed 100, so I added a dimension to the DP array to control the number of coins.
This topic lists the types of coins, so you only need to create a table first.
Coin change
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 8112 accepted submission (s): 2696
Problem descriptionsuppose there are 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 have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. so there are four ways of making changes for 11 cents
With the above coins. Note that we count that there is one way of making change for zero Cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program shocould be able to handle up to 100 coins.
Inputthe input file contains any number of lines, each one consisting of a number (≤ 250) 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 coins.
Sample Input
1126
Sample output
413
# Include <iostream> using namespace STD; int DP [110] [350]; // [quantity] [amount of money] int ans [350]; int main () {int KK; int A [] = {1, 5, 10, 25, 50}; memset (DP, 0, sizeof (DP); DP [0] [0] = 1; for (INT I = 0; I <5; I ++) // name the table {for (Int J = 1; j <= 100; j ++) // control the number of coins for (int K = A [I]; k <300; k ++) // exchange the denomination {If (DP [J-1] [k-A [I]) {DP [J] [k] = DP [J] [k] + dp [J-1] [k-A [I] ;}} memset (ANS, 0, sizeof (ANS); For (INT I = 0; I <300; I ++) {for (Int J = 0; j <= 100; j ++) ans [I] + = DP [J] [I];} int aim; while (CIN> aim) cout <ans [aim] <Endl; return 0 ;}