Example
Input
knapsack([60,100,120],[10,20,30],50)
Output
220
Choose items with weights 20 and 30 for total value 100 + 120 = 220.
Full lesson preview
Implement the 0/1 knapsack DP to compute the maximum value achievable within a capacity constraint.
Problem statement
Task
Examples
Input
knapsack([60,100,120],[10,20,30],50)
Output
220
Choose items with weights 20 and 30 for total value 100 + 120 = 220.
Input format
Output format
Constraints
Samples
Input
knapsack([1,2,3],[1,1,1],2)
Output
5
Choose the two items with highest values (3 and 2) for total value 5.