Data Structures & AlgorithmsHardGATE 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 15. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 15?
- A. 26
- B. 1757
- C. 878
- D. 15
Correct answer: B. 1757
Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 1757. Leaving out doubling gives 610, and leaving out the +2 step gives 26.
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 pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 2, 4} and s ≤ the pile size. The player who…
- An undirected graph has the vertices D, N, P, W, Z and the edges W–D, W–P, W–Z, D–N, N–Z. In how many ways can each vertex be given one of…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 3) return g(n - 3) - 1 What value does…
- A grid has 7 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): .......# ...#.... ..#..... .#.#.##. .#..#…
- Two unmarked jugs hold 7 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- 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…