#C10079. Coin Sum Possibility
Coin Sum Possibility
Coin Sum Possibility
You are given a set of coin denominations, and your task is to determine whether it is possible to form a target sum s using any combination of the coins. You may use each coin type an unlimited number of times.
The problem can be formulated using the following recurrence in dynamic programming:
[ dp[i] = \bigvee_{\text{coin } c \text{ such that } i-c \ge 0} dp[i-c] ]
with the base case \(dp[0]=\text{True}\). If \(dp[s]=\text{True}\), then the answer is POSSIBLE
; otherwise, it is IMPOSSIBLE
.
inputFormat
The first line of input contains an integer Q representing the number of queries. Each query is described with two lines:
- The first line contains two integers n and s, where n is the number of coin denominations and s is the target sum.
- The second line contains n space-separated integers representing the coin denominations.
Note: There is no constraint that the coins are in any particular order, and each coin can be used an unlimited number of times.
outputFormat
For each query, output a single line containing either POSSIBLE
if the target sum can be formed, or IMPOSSIBLE
otherwise.
1
3 11
1 2 5
POSSIBLE
</p>