Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
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 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. 6
- B. 5
- C. 7
- D. 13
Correct answer: B. 5
Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 5 losing piles in 1 to 18. Counting the winning ones instead gives 13, and including pile 0 gives 6.
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 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…
- Bellman–Ford is run from source P on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: Z→S…