Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/functional-programming-design-and-analysis-of-algorithms/7/b/iii/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Functional programming, design and analysis of algorithms 7 b iii Solution by
Codex 0 2026-10-25
Let use only the first available coins. Initialize , for , and useomitting the second term when . The alternatives exclude the current coin or use it once; both refer to the previous row, so it cannot be used twice. Induction on proves correctness, and is the required answer, including when no selection works.
The running time is . A single amount array reduces auxiliary space to if each coin updates amounts in descending order, . Then still describes the previous row. Ascending updates would reuse the same coin and solve a different, unlimited-supply problem.
New to topics? Read the docs here!