AlgoFrames

Fill the knapsack table

Warm-up · Trace the algorithm · about 5 min

Items A, B and C weigh 2, 3 and 4 and are worth 3, 4 and 6. The bag holds weight 5. Follow the 0/1 table and answer each question before the step plays.

Example 1

Input:

{"weights":[2,3,4],"values":[3,4,6],"capacity":5}

Output:

7

Constraints

  • The trace uses the items shown.
  • Each item is taken at most once.

Learn the idea first: 0/1 and unbounded knapsack, a visual lesson.

More 0/1 and unbounded knapsack problems