Data Structures & AlgorithmsHardGATE CS · ICPC regional
Coins of denominations [12, 9, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 16? (Coins may be used any number of times; the answer must sum exactly.)
- A. 3
- B. 16
- C. 2
- D. 4
Correct answer: C. 2
The unbounded DP gives 2 coins. The greedy largest-first rule uses 3, which is the trap when denominations are not canonical.
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
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), A–F (1), B–D (1), B–E (1), B–F (1), B–G (1), C–E (1)…
- Array A = [9, 4, 4, 8, 1, 7, 2] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (2, 2) and must reach (6, 0) (as (row, column)). A knight…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–B (1), A–C (1), A–D (1), A–G (1), A–H (1), B–C (1), B–H (1)…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): A→B (4); D→C (8); B→A (8); D→B (7); A→C (8). Let d(x, y) be the…
- Array A = [2, 8, 4, 1, 10, 9, 8]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…