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/b/solution

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.

New to topics? Read the docs here!