#QHD0000071. Đổi tiền với giới hạn số đồng (Coin Changing Again)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đổi tiền với giới hạn số đồng (Coin Changing Again)
Coin Changing Again
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are four distinct coin denominations . Each query specifies upper bounds on how many coins of each type can be used, and a target value .
Count the number of integer quadruples satisfying and . Coin order does not matter, only multiplicities. Print zero if no such combination exists, without reducing the answer modulo anything.
All queries share the same four denominations and belong to one input instance. Print one answer per query in the original order. For denominations , bounds , and target , exactly four combinations are possible.
Input
The first line contains . Each of the following lines contains .
Output
Print lines containing the exact number of valid combinations for each respective query.
Subtasks
- Subtask 1 (20 points): ; ; ; for every query.
- Subtask 2 (30 points): ; ; ; for every query.
- Subtask 3 (50 points): ; ; ; for every query.
Examples
Input
1 2 5 10 2
3 2 3 1 10
1000 2 2 2 900
Output
4
27
Explanation
The first query has four valid multiplicity vectors: , , and . The second query produces valid combinations of total .