Let item have weight and profit . Define as the largest profit obtainable from the first items with capacity at most the nonnegative integer . Set . The last item is either absent or present once, giving the dynamic programming recursionThe two alternatives exhaust the feasible binary decisions. In the second alternative, deleting item leaves exactly the smaller subproblem with capacity , which proves the recurrence.
Fill rows , and within each row capacities . Store which alternative attains each maximum. Backtrack from : when exclusion was chosen, set and move to ; when inclusion was chosen, set and move to . Ties may be resolved either way. Thus the stored values yield an actual optimal selection, not just its objective value.
For items and capacity , the algorithm uses arithmetic operations and space with the full backtracking table. It is a pseudo-polynomial algorithm, since is a numerical capacity rather than its bit length. A value-only version can use one row, but must update capacities in decreasing order to avoid reusing the same item.
Articles by others on the same topic
There are currently no matching articles.