Question: Problem 1 - Santa (Java) The Christmas season is not anymore the time for Santa Claus to deliver gifts to every person on the earth.
Problem 1 - Santa (Java)
The Christmas season is not anymore the time for Santa Claus to deliver gifts to every person on the earth. He now wants to take things away from people.
When he enters Gigel's house, he finds N objects, and each object may weigh up to 1000 grams. Santa Claus needs to know if there is a subset of objects in Gigel's house whose combined weight is equal to W because he can only carry a maximum of W grams in his backpack.
Help Santa know whether he can steal objects from the following M houses, knowing that his backpack's maximum weight changes at each house he visits.
Data format
Input
The input file is called santa.in.
The first line contains the number of houses M.
The second line contains the number of objects N from the first house, followed by the maximum weight of the backpack W available for the first house.
Each of the next N lines contains one integer Gi, which represents the weight of the object i, that Santa finds in the first house.
Output
The output file is called santa.out.
It contains only one line with the word yes, if exists a subset of objects whose combined weight is equal to W, or no if there is no such subset of objects
Data limits
1 <= N <= 20
1 <= Gi <= 1000
1 <= M <= 300
Example:
| santa.in | santa.out |
| 2 7 152 19 18 11 999 6 135 229 4 17 1 5 5 13 | yes no |
Explanation:
There are 2 houses in total.
The objects from the first house that have the weight 11, 6 and 135 have a total weight of 152 (11 + 6 + 135 = 152).
There are no objects from the second house that summed together have a total weight of 17.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
