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 22. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 22?
- A. 22
- B. 17711
- C. 74
- D. 52935
Correct answer: D. 52935
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 52935. Leaving out doubling gives 17711, and leaving out the +2 step gives 74.
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
- Starting from the integer 9, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- An undirected graph has the vertices A, O, S, T, V, Y and the edges Y–V, T–A, T–V, O–T, O–A, Y–A, S–V, O–S, V–A. What is the minimum…
- An undirected graph has the vertices M, O, U, Y and the edges U–O, U–Y, M–O, O–Y. In how many ways can each vertex be given one of 3…
- The directed acyclic graph has the vertices B, C, K, P, Q, R, V, Z and the arcs Z→V, K→R, C→B, K→C, Q→B, Z→B, Z→K, R→V, Q→Z, P→R, K→B…
- A directed graph has the vertices C, D, F, G, H, I, Q, W and the arcs I→H, I→D, I→F, I→W, Q→D, Q→F, Q→G, Q→C, H→F, H→W, H→C, F→I, F→Q…
- A directed acyclic graph has the vertices A, D, M, O, Q, U, V and the edges U→M, U→D, U→V, Q→U, Q→O, A→M, A→V, O→U. A topological order…