UVA 357 let Me Count the Ways

Source: Internet
Author: User

Let Me Count the Ways

Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

After making a purchase at a large department store, Mel's change was to cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he is shopping at a convenience store. Again he was cents. This time he received 2 nickels and 7 pennies. He began to wonder ' what many stores can I shop in and receive from cents change in a different configuration of coins? After a suitable mental struggle, he decided the answer was 6. He then challenged your to consider the general problem.

Write a program which would determine the number of different combinations of US coins (penny:1c, nickel:5c, dime:10c, q UARTER:25C, half-dollar:50c) which may is used to produce a given amount of money.

Input

The input would consist of a set of numbers between 0 and 30000 inclusive, one per line in the input file.

Output

The output would consist of the appropriate statement from the selection below on a the output file for each Input value. The numberm is the number your program computes, and n is the input value.

there is m ways to produce N cents Change.

there is only 1-to-produce N cents Change.

Sample Input

17 114

Sample Output

There is 6 ways to produce-cents change. There is 4 ways to produce one cents change. There is the only 1-by-produce 4 cents change.


State transfer equation: dp[j] + = Dp[j-a[i]; A[i] What kinds of currencies are they? The data is large, and the DP array is long long. First hit the table, then directly output the line.

#include <stdio.h> #include <string.h>long long int  dp[30005];int a[5] ={1,5,10,25,50};int main () { Memset (Dp,0,sizeof (DP));DP [0] = 1;for (int i = 0;i < 5;i++) for (int j = a[i];j <= 30000;j++) dp[j] + = dp[j-a[i]]; int X;while (~SCANF ("%d", &x)) {if (X < 5) printf ("There is the only%d-through to produce%d cents change.\n", 1,x); elseprintf (" There is%lld ways to produce%d cents change.\n ", dp[x],x);} return 0;}

Input

Output

Sample Input

Sample Output

Hint


UVA 357 let Me Count the Ways

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.