#P1450. Coin Payment Combinations
Coin Payment Combinations
Coin Payment Combinations
There are 4 types of coins with denominations (c_1), (c_2), (c_3), and (c_4). A person goes shopping (n) times. For each purchase, he takes (d_i) coins of type (i) (for (i=1,2,3,4)) and wishes to pay exactly (s) in value. Determine the number of ways he can make the payment.
Each valid way is a selection of coins such that the total value adds up to (s) without using more than the available coins.
inputFormat
The first line contains four integers: (c_1), (c_2), (c_3), and (c_4). The second line contains an integer (n), the number of test cases. Each of the next (n) lines contains five integers: (d_1), (d_2), (d_3), (d_4), and (s), where (d_i) is the number of coins of type (i) available and (s) is the target sum.
outputFormat
For each test case, output a single line containing the number of ways to pay exactly (s) using the coins available.
sample
1 2 5 10
3
2 2 1 1 10
0 0 0 1 10
3 2 2 1 14
2
1
4
</p>