UVA 674 Coin Change
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
11
26
Sample Output
4
13
There are 5 kinds of coins: 1 points, 5 points, 10 points, 25 points, 50 points. Given the total amount of money N, asked to use 5 kinds of coins, how many kinds of composition. Problem-solving ideas: recursion.
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace STD;intdp[8000], coin[5] = {1,5,Ten, -, -};intMain () {intN while(scanf("%d", &n)! = EOF) {memset(DP,0,sizeof(DP)); dp[0] =1; for(inti =0; I <5; i++) { for(intj = Coin[i]; J <= N; J + +) {if(Dp[j-coin[i]]) {Dp[j] + = dp[j-coin[i]]; } } }printf("%d\n", Dp[n]); }return 0;}
UVA 674 Coin Change (DP)