UVa 674 Coin Change (DP)

Source: Internet
Author: User
Tags time limit

674-coin Change

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_ problem&problem=615

Suppose there are 5 types of coins:50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with the coins for a given amount of.

For example, if we have cents, then we can make changes with one 10-cent coin and one 1-cent coin, two 5-cent coins and One 1-cent coin, one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways to making changes for one cents with the above. Note this we count that there is one way 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 of number for the amount of the.

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

One
26

Sample Output

4
13

Thinking: From the top down analysis, um ... A five-pronged tree.

So simply push it from the bottom up: dp[i] = Dp[i] + dp[i-coin[k]]

Complete code:

/*0.042s*/
  
#include <cstdio>
#include <cstring>
const int MAXN = 7490;
const int Coin[5] = {1, 5, ten};
  
int DP[MAXN];
  
int main (void)
{
    int n;
    memset (DP, 0, sizeof (DP));
    Dp[0] = 1;
    for (int k = 0; k < 5, ++k) for
        (int i = coin[k]; i < MAXN ++i)
            dp[i] + = dp[i-coin[k]];///Various combinations are superimposed 
  while (~scanf ("%d", &n))
        printf ("%d\n", Dp[n]);
    return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.