#K46237. Unbounded Subset Sum Problem

    ID: 27932 Type: Default 1000ms 256MiB

Unbounded Subset Sum Problem

Unbounded Subset Sum Problem

You are given a list of positive integers (coins) and a target sum \(S\). Determine whether it is possible to form \(S\) by using any number of coins, where each coin may be used an unlimited number of times.

This problem is a variant of the unbounded knapsack problem. Use the following recurrence relation to solve it:

[ dp[i] = dp[i] \lor dp[i - a_j] \quad \text{for all } i \geq a_j, ]

where \(a_j\) represents the coin values. The answer for each test case should be printed in the format Case x: YES if \(S\) can be formed, and Case x: NO otherwise.

inputFormat

The input begins with an integer \(T\) (the number of test cases). Each test case is described as follows:

  • The first line of each test case contains two integers \(n\) and \(S\) where \(n\) is the number of coins and \(S\) is the target sum.
  • The second line contains \(n\) space-separated positive integers representing the coin values.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single line in the format Case x: YES if the target sum can be formed, or Case x: NO if it cannot. All output should be written to standard output (stdout).

## sample
3
5 11
2 3 7 8 10
4 5
2 4 6 8
3 7
1 2 3
Case 1: YES

Case 2: NO Case 3: YES

</p>