UVA 674 Coin Change (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.