Bounded knapsack problem Created 2026-10-20 Updated 2026-11-05
The bounded knapsack problem adds per-type upper limits to the integer knapsack problem. It interpolates between 0-1 knapsack problem () and the unbounded knapsack problem.
Processing types one at a time gives . The previous-type index prevents the recurrence from exceeding the allowed count. For large , splitting counts into power-of-two bundles and a final remainder reduces the bounded type to logarithmically many 0-1 knapsack problem items while preserving every allowable count.
For the unbounded knapsack problem, let be the greatest total value obtainable with weight at most capacity . Assume positive integer item weights and nonnegative integer capacity . Set , and fill increasing capacities using
The zero alternative permits unused capacity. If a nonempty optimum includes item , removing one copy leaves a feasible smaller-capacity instance; its remaining value cannot exceed . Conversely every candidate in the displayed maximum is feasible, proving equality. The smaller-capacity state allows the same type again, implementing repetition.
The answer is , computed in time and space. Record an attaining item at each state to reconstruct the multiset. This is pseudopolynomial time, because is a number whose binary representation may have only bits. A positive-value zero-weight type would make the optimum unbounded and must be excluded or detected separately.
Use positive integral item weights and a nonnegative integral capacity. For the unbounded knapsack problem, define to be the best value with total weight at most . Then
The zero candidate is the empty selection, so unused capacity is allowed and an empty set of fitting items causes no problem. Every nonempty feasible selection has some last item ; removing one copy leaves a feasible solution at capacity . Its value is bounded by the corresponding candidate. Conversely, taking an optimal smaller selection and adding that item attains the candidate, proving the recurrence relation by optimal substructure. Positive weights make every dependency strictly smaller.
Fill capacities in increasing order. There are entries, each scanning items, so the dynamic programming takes time and storage. A winning item pointer at each capacity reconstructs the chosen multiplicities. These are capacity-dependent, pseudopolynomial bounds. For zero-weight items, any positive value makes the repetition problem unbounded; nonpositive-value zero-weight items may simply be discarded before using the recurrence.
Unbounded knapsack problem Created 2026-10-20 Updated 2026-11-05
In the unbounded knapsack problem, each item type may be used any nonnegative integer number of times. With positive integer weights , values and capacity , maximize subject to and .
A dynamic programming recurrence for capacity-at-most value is . Evaluate capacities in increasing order so repeated uses are available. With weights three and five, values four and seven, and capacity ten, two weight-five items give value fourteen. A zero-weight positive-value item would make the objective unbounded, explaining the positive-weight hypothesis.