A ticket kiosk gives change using k distinct coin denominations, with an unlimited supply of each. Count the number of distinct ways to make change for amount T using these coins, where two ways are considered the SAME if they use the same number of coins of each denomination (the order in which coins are handed over does not matter). Since the count can be large, print it modulo 1000000007.
Line 1: two integers T k.
Line 2: k distinct space-separated positive integers, the coin denominations.
A single integer: the number of distinct multisets of coins summing to exactly T, modulo 1000000007. (If T = 0, the only way is to use no coins, so the answer is 1.)
Example 1
Input
5 2 1 2
Expected
3
Explanation
The ways to make 5 from 1s and 2s are 1+1+1+1+1, 1+1+1+2, and 1+2+2 — 3 combinations.
Example 2
Input
3 1 2
Expected
0
Explanation
With only 2-value coins, an odd amount like 3 can never be reached: answer 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →