Knapsack

items is a list of (weight, value) pairs and the bag holds at most capacity weight. Each item can be taken once or not at all. Write best_value(items, capacity) that returns the largest total value that fits.

best_value([(1, 1), (3, 4), (4, 5), (5, 7)], 7)  ->  9     (3 + 4)
best_value([(5, 10)], 4)                        ->  0

The point is to practise the 0/1 knapsack table, the take-or-skip recurrence over capacities.

def best_value(items, capacity):
    ...