Practice Discrete Math

Algorithms / Knapsack Family

Least You Need to Know: Knapsack Family, Capacity States, and Reuse vs One-Time Choice

Knapsack questions are about resource budgets. The main design choice is whether each item may be used once, infinitely often, or only for feasibility, because that determines the state meaning and the update order that keeps the recurrence honest.

The least you need to know

Key notation

dp[c] best value or feasibility summary at capacity `c`
0/1 each item usable at most once
complete an item may be taken repeatedly

Tiny worked example

  • In 0/1 knapsack, after considering an item of weight `w`, updating capacities from high to low prevents the same item from being counted twice.
  • In complete knapsack, low-to-high updates are appropriate because reusing the current item is allowed.

Common mistakes

How to recognize this kind of problem

Start practice