#QHD0000066. Có bao nhiêu cách đổi tiền? (Let Me Count The Ways)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Có bao nhiêu cách đổi tiền? (Let Me Count The Ways)
Let Me Count The Ways
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
After shopping, someone receives cents in change. On one occasion the change consists of a -cent coin, a -cent coin, and two pennies; on another occasion it consists of two -cent coins and seven pennies. These are different combinations of coins with the same total value. The task is to count all distinct combinations for any given amount.
This problem uses the five standard US coin denominations , , , , and cents. There are unlimited quantities of every denomination. Two combinations differ only if the number of coins of at least one denomination differs; the order in which coins are given does not distinguish combinations.
Given a nonnegative amount in cents, compute the exact number of combinations that produce , including (which has one empty combination). Do not take the count modulo any number. The result may exceed the range of a signed -bit integer.
Instead of printing only the count, you must output one of two exact English sentences. One sentence is used when there is exactly one combination, and the other is used when there are multiple combinations.
Input
One line contains an integer , the target amount in cents.
Output
If exactly one combination exists, print exactly: There is only 1 way to produce n cents change. with n replaced by the input value.
If there are combinations, print exactly: There are m ways to produce n cents change. with m and n replaced by their values. Preserve capitalization, spacing, and the final period.
Subtasks
-
Subtask 1 (20 points): ; unlimited coins of denominations , , , , cents.
-
Subtask 2 (30 points): ; unlimited coins of denominations , , , , cents.
-
Subtask 3 (50 points): ; unlimited coins of denominations , , , , cents.
Examples
Input
17
Output
There are 6 ways to produce 17 cents change.
Explanation
For , denominations and cannot be used. Without a -cent coin, one may use , , , or nickels, with the rest made up by pennies, giving four combinations. With one -cent coin, one may use or nickel, giving two additional combinations. Thus there are combinations and the plural sentence is required. At , there is only one combination, four pennies, so the singular sentence is used.