Question | Knapsack
You’re are a thief, and your job is to pick among n
items that are of different weights and values. You have a knapsack that supports ‘c’ pounds, and you want to pick some subset of the items so that you maximize the value you’ve stolen.
Define knapsack
, which takes a list weights
, list values
and a capacity c
, and returns that max value.
You may assume that item 0 weighs weights[0]
pounds, and is worth values[0]
; item 1 weighs weights[1]
pounds, and is worth values[1]
; etc.
def knapsack(weights, values, c):
"""
>>> w = [1.5, 4, 3, 3]
>>> v = [1, 5, 2, 3]
>>> knapsack(w, v, 6)
6
"""
## YOUR CODE HERE ##