Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Coins of denominations [6, 5, 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. 5
- C. 16
- D. 4
Correct answer: A. 3
The unbounded DP gives 3 coins. The greedy largest-first rule uses 4, 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
- Words ['b', 'a', 'aaba', 'cab', 'baca', 'b'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Array A = [30, 20, 28, 25, 2, 19, 15, 7, 11]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–F (1), A–G (1), B–C (1), B–E (1), C–E (1), D–E (1), E–H (1)…
- Array A = [11, 19, 21, 15, 20] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), A–D (1), A–E (1), C–E (1), C–F (1), C–G (1), D–F (1)…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [11, 8, 3, 12, 16, 9], where Mi has size p[i−1] × p[i]…