The 0/1 Knapsack
Each item has a weight and a value and can be taken at most once. Maximize the total value within capacity W.
Input: the first line has N and W; each of the next N lines has wi and vi.
Output: the maximum total value.
Constraints:
- 1 ≤ N ≤ 100
- 1 ≤ W ≤ 1000
- 1 ≤ wi ≤ 1000
- 0 ≤ vi ≤ 104
Sample Tests
Input 1
3 8 3 30 4 50 5 60
Output 1
90
Input 2
1 1 2 100
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.