Counting Coin Combinations
InterviewTime limit1sMemory limit128 MB
Count the number of ways to sum a set of coin denominations (unlimited use, order ignored) to reach a target amount, for multiple test cases.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Given several coin denominations and a target amount, count how many distinct combinations of coins can make that amount.
Each denomination may be used any number of times. Two ways that differ only by the order of the coins are considered the same combination.
Input
The first line contains the number of test cases T.
Each test case consists of three lines.
- The first line contains the number of coin denominations
N(1 <= N <= 20). - The second line contains the
Ncoin values in increasing order. Each value is an integer from1to10000. - The third line contains the target amount
M(1 <= M <= 10000).
You may assume that the number of combinations is less than $2^{31}-1$.
Output
For each test case, print one line containing the number of combinations that make amount M using the given denominations.