Objective
You have a knapsack with limited capacity and items with weight and value. Each item is taken whole or not at all. The table dp[w] stores the best value with capacity w; walking it from high to low avoids using an item twice.
Instructions
- The first line has
n capacity(number of items and capacity); thennlinesweight value. - Show
Maximum value: x.
3 50
10 60
20 100
30 120
Maximum value: 220
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise