Uva674--dp--coin Change

Source: Internet
Author: User

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

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.