Data Structures & AlgorithmsHardGATE CS · ICPC regional
Coins of denominations [2, 9, 15, 17] are available in unlimited supply. What is the minimum number of coins needed to pay exactly 57?
- A. 5
- B. 6
- C. 4
- D. 17
Correct answer: A. 5
The greedy rule (largest coin first) is optimal only for canonical coin systems. Here a dynamic program over amounts finds a smaller coin count than greedy. The number of ways to pay is a different question.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Coins of denominations [2, 10, 16] are available in unlimited supply. What is the minimum number of coins needed to pay exactly 30?
- The naive recursion fib(n) = fib(n − 1) + fib(n − 2), with base cases fib(0) = 0 and fib(1) = 1, is started by calling fib(6). Counting…
- The naive recursion fib(n) = fib(n − 1) + fib(n − 2), with base cases fib(0) = 0 and fib(1) = 1, is started by calling fib(7). Counting…
- The naive recursion fib(n) = fib(n − 1) + fib(n − 2), with base cases fib(0) = 0 and fib(1) = 1, is started by calling fib(8). Counting…
- The naive recursion fib(n) = fib(n − 1) + fib(n − 2), with base cases fib(0) = 0 and fib(1) = 1, is started by calling fib(9). Counting…
- The naive recursion fib(n) = fib(n − 1) + fib(n − 2), with base cases fib(0) = 0 and fib(1) = 1, is started by calling fib(10). Counting…