Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2018/functional-programming-design-and-analysis-of-algorithms/6/d/solution

Each physical item may enter neither knapsack or exactly one of them. Let be the largest combined value using the first items with remaining capacity limits . Initialize and compute
An infeasible alternative is omitted. The three alternatives classify the placement of item exhaustively. Every reference uses row , ensuring that no item is placed in both knapsacks. Removing item from an optimum and applying optimal substructure proves the recurrence relation.
The optimum is , with time , conventionally for positive capacities. Two successive layers require space; keep predecessor decisions or recompute them if the actual allocations are wanted. The stipulated uniqueness of values and weights is unnecessary for correctness. The capacity-indexed algorithm is pseudopolynomial.

New to topics? Read the docs here!