Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
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 ≤ 24 is the position a LOSS for the player to move?
- A. 8
- B. 16
- C. 9
- D. 12
Correct answer: A. 8
Mark positions from 0 upward: with moves {1, 2, 4} the losing piles are exactly the multiples of 3 (3, 6, ..., 24), so 8. Counting winners gives 16, including pile 0 gives 9, and assuming every even pile loses gives 12.
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 tree has the vertices F, G, J, T, U, W, Y and the edges G–T, T–Y, G–U, Y–J, J–W, W–F. What is the minimum number of vertices needed so…
- A directed graph has the vertices A, E, J, M and the arcs M→E, M→J, M→A, E→A, J→M, J→A, A→M, A→E, A→J. Count the directed Hamiltonian…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): A–F (17), S–P (22), F–P (29), A–P (10), A–S…
- An undirected graph has the vertices D, M, P, Q, Y and the edges Q–P, Q–D, P–M, P–Y, M–D. A walk may repeat vertices and edges. How many…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has the vertices E, F, G, I, K, N, Y and the edges G–F, G–N, F–E, N–K, K–Y, K–I. A centroid is a vertex whose removal leaves no…