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 {4, 5, 6} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 18 is the position a LOSS for the player to move?
- A. 7
- B. 11
- C. 8
- D. 9
Correct answer: A. 7
Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 7 losing piles in 1 to 18. Counting the winning ones instead gives 11, and including pile 0 gives 8.
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 {2, 3, 5} and s ≤ the pile size. The player who…
- A directed acyclic graph has the vertices A, E, F, J, S, U and the arcs A→E, A→S, A→F, E→J, E→S, E→F, E→U, J→U, F→U. Two players…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {3, 4, 6} and s ≤ the pile size. The player who…
- A tree has the vertices C, F, G, I, N, R, S and the edges R–G, R–S, S–I, I–C, C–F, R–N. A set D dominates the tree if every vertex is in D…
- A tree has the vertices B, C, F, K, M, N, Q, R, X, Z and the edges C–X, X–Z, X–M, M–K, C–B, Z–R, B–Q, M–N, N–F. What is the minimum number…
- A tree has vertices with values in brackets: M[0], R[5], A[9], G[-4], H[9]. The edges are M–R, M–A, R–G, M–H. A path is any sequence of…