Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 24. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 24?
- A. 24
- B. 46368
- C. 138805
- D. 69402
Correct answer: C. 138805
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 138805. Leaving out doubling gives 46368, and leaving out the +2 step gives 94.
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
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→4 (4), 2→1 (1), 2→3 (4), 3→1 (5), 3→4 (10), 4→1 (6), 4→2 (6), 4→3…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 17. Two sequences of steps…
- A grid has 8 rows and 5 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): .#.## ..... #...# .#... ..... ..##. ....#…
- A tree has the vertices D, G, O, Q, T, Y, Z and the edges T–Y, Y–G, Y–D, G–Q, T–Z, Z–O. What is the minimum number of vertices needed so…
- A tree has vertices with values in brackets: J[0], N[0], I[8], Q[3], K[-2]. The edges are J–N, N–I, N–Q, I–K. A path is any sequence of…
- Cities H, J, L, T, W are joined by roads with these travel costs: H–T 6, H–W 9, H–L 19, H–J 19, T–W 19, T–L 20, T–J 15, W–L 13, W–J 14…