#QHD0000087. Đếm cách thanh toán (Pay the Price)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm cách thanh toán (Pay the Price)
Pay the Price
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
In a country, coin denominations are all integers from to , with unlimited availability of each denomination. To pay exactly units, choose a multiset of coins summing to . Two payment methods are the same if they use the same count of each denomination; changing the order of the coins does not make a new method. For example, paying using exactly three coins has three methods: , , and .
The input specifies one of three possible restrictions on the number of coins:
- Only : any number of coins is allowed, provided they sum to .
- and : use at most coins.
- : use at least and at most coins, with both endpoints included.
Count the distinct methods satisfying the specified limit. For , the empty payment is one method if zero coins are permitted. No valid payment of value can contain more than coins because all denominations are positive.
PHOJ adaptation: The original UVa input contains many independent query lines until end-of-file. This version takes one query and prints one answer; no EOF loop or sentinel is used.
Input
One line contains one, two, or three integers: n, n U, or n L U. The number of integers determines the query type.
Output
Print a 64-bit integer: the number of distinct payment methods. Do not take any modulus.
Subtasks
-
Subtask 1 (20 points): ; supplied limits are in and lower limit does not exceed upper.
-
Subtask 2 (30 points): ; supplied limits are in .
-
Subtask 3 (50 points): ; supplied limits may be between and , with when both are present.
Examples
Example 1
Input
6 2 5
Output
9
Explanation: Of the 11 unrestricted partitions of 6, remove the single-coin method and the six-coin method, leaving 9.
Example 2
Input
6
Output
11
Explanation: There are 11 integer partitions of 6, hence 11 payment methods.
Example 3
Input
6 3
Output
7
Explanation: Exactly seven partitions of 6 use at most three positive parts.