#C1993. Exact Target Weight Achievement
Exact Target Weight Achievement
Exact Target Weight Achievement
You are given several test cases. In each test case, you have an unlimited supply of fruits, each with a specific weight. Your task is to determine whether it is possible to reach an exact target weight by using any combination of the available fruits.
Formally, for each test case, you are given an integer n that denotes the number of different fruit types, followed by a list of n positive integers representing the weights of these fruits, and finally an integer W representing the target weight. You can use each fruit type an unlimited number of times. Determine if there exists any combination such that the sum of the selected fruits equals W.
The problem can be formulated using the following equation in LaTeX:
\(\sum_{i=1}^{n} a_i \times w_i = W\)
where \(a_i\) is a non-negative integer (possibly 0) representing the count of the fruit with weight \(w_i\).
For each test case, output "Yes" if such a combination exists, otherwise output "No".
inputFormat
The first line of input contains a single integer T indicating the number of test cases. The description of the test cases follows.
For each test case, the input is given in the following format:
- The first line contains an integer n — the number of different fruit types.
- The second line contains n space-separated integers, each representing the weight of a fruit.
- The third line contains an integer W — the exact target weight.
All input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing either "Yes" or "No", indicating whether the target weight can be achieved using any combination of the given fruits.
All output should be written to standard output (stdout).
## sample3
3
2 3 7
11
4
5 10 20 25
1
2
6 9
15
Yes
No
Yes
</p>