Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 23. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 23?
- A. 23
- B. 42727
- C. 85455
- D. 74
Correct answer: C. 85455
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 85455. Leaving out doubling gives 28657, 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
- Bellman–Ford is run from source S on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: S→E…
- Cities J, O, Q, V, X, Y are joined by roads with these travel costs: X–J 4, X–Q 5, X–Y 7, X–V 6, X–O 2, J–Q 8, J–Y 4, J–V 5, J–O 9, Q–Y…
- An undirected graph has the vertices C, E, F, L, U, X, Z and the edges L–C, C–U, X–L, E–C, Z–L, E–U, F–L, Z–C, E–Z, X–U. How many simple…
- An undirected graph has the vertices F, I, M, Q, T and the edges I–Q, Q–M, I–F, Q–F, I–T, T–Q, T–M, I–M, T–F. What is the minimum number…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- An undirected connected graph on the vertices H, K, L, V has the edges L–K, V–H, H–K, V–K, L–H, V–L. How many spanning trees does it have?…