Data Structures & AlgorithmsVery hardCodeforces Div 2 D · 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 19. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 19?
- A. 12346
- B. 6173
- C. 46
- D. 19
Correct answer: A. 12346
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 12346. Leaving out doubling gives 4181, and leaving out the +2 step gives 46.
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
- An undirected graph has the vertices D, M, R, V and the edges M–D, M–V, M–R, D–V, D–R, V–R. A walk may repeat vertices and edges. How many…
- The directed acyclic graph has the vertices A, B, C, G, J, O and the arcs J→C, G→C, J→O, J→A, G→A, J→B, B→C, O→B. How many distinct…
- A tree has vertices with weights in brackets: T[6], C[15], K[8], Z[3], U[2], V[2], N[14], G[14], F[1], H[7]. The edges are T–C, T–K, K–Z…
- The directed acyclic graph has the vertices D, E, J, L, N, Q, S, Z and the arcs D→Q, Z→N, N→Q, Q→S, D→J, E→S, L→Q, E→Q, D→N, E→N, J→Q…
- A connected undirected graph has the vertices A, D, E, F, H, J, M, Z and the edges J–Z, J–D, J–F, J–M, Z–F, Z–H, Z–E, D–A, D–F, A–E, F–E…
- On an 8×8 chessboard, rows and columns are numbered 0 to 7, and squares are written (row, column). A knight moves in the usual L-shape…