Transport
InterviewTime limit1sMemory limit128 MB
With at most 20 items, choose a subset whose total weight is at most W and whose total value is as large as possible.
- Level
Medium4 of 10
- Topics
- Brute force, Backtracking, Dynamic programming
- Solved
- No attempts yet
Problem
You have a transport plane that must deliver items to a remote location. You would like to load all of the items, but you cannot exceed the plane's weight capacity . Given items with known weights and values , find the most valuable subset of the items that fits into the plane without exceeding the capacity .
Input
The first line contains a positive integer indicating the number of problem sets. Each problem set begins with a line containing two positive integers and , where is the number of items and is the capacity of the plane. The next lines each contain two integers and , where is the weight and is the value of an item. All weights and values are positive integers, and the number of items in any problem set is at most 20.
Output
For each problem set, print on its own line the total value of the most valuable subset that the plane can transport without exceeding its capacity .