Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 20. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 20?
- A. 20174
- B. 6765
- C. 10087
- D. 60
Correct answer: A. 20174
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 20174. Leaving out doubling gives 6765, and leaving out the +2 step gives 60.
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
- A grid has 4 rows and 4 columns (top to bottom; '.' open, '#' blocked): ..## .... .... .... You may only move right or down, and you…
- An undirected connected graph on the vertices D, H, I, K, M has the edges H–K, I–K, D–H, D–M, D–K, D–I, H–M, M–K, H–I. How many spanning…
- An undirected graph has the vertices R, T, V, X and the edges T–R, T–X, T–V, R–V, X–V. A walk may repeat vertices and edges. How many…
- A connected undirected graph has the vertices B, D, J, K, Q, X and the edges X–J, X–B, X–D, J–B, J–Q, J–K, J–D, B–K, B–D. Parallel edges…
- A connected undirected graph has the vertices A, F, I, M, Q, S, X and the edges M–Q, M–S, M–A, M–X, Q–S, S–F, A–I. How many bridges does…
- Bellman–Ford is run from source C on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→F…