DP algorithm for bounded Knapsack?

lithuak picture lithuak · Mar 5, 2012 · Viewed 11.5k times · Source

The Wikipedia article about Knapsack problem contains lists three kinds of it:

  1. 1-0 (one item of a type)

  2. Bounded (several items of a type)

  3. Unbounded (unlimited number of items of a type)

The article contains DP approaches for 1. and 3. types of problem, but no solution for 2.

How can the dynamic programming algorithm for solving 2. be described?

Answer

Irit Katriel picture Irit Katriel · Mar 5, 2012

Use the 0-1 variant, but allow repetition of an item in the solution up to the number of times specified in its bound. You would need to maintain a vector stating how many copies of each item you already included in the partial solution.