Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
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 cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 22 is the position a LOSS for the player to move?
- A. 15
- B. 8
- C. 7
- D. 11
Correct answer: C. 7
Mark positions from 0 upward: with moves {1, 2, 4} the losing piles are exactly the multiples of 3 (3, 6, ..., 21), so 7. Counting winners gives 15, including pile 0 gives 8, and assuming every even pile loses gives 11.
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, 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…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…