Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 5} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 25 is the position a LOSS for the player to move?
- A. 10
- B. 11
- C. 14
- D. 13
Correct answer: B. 11
Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 11 losing piles in 1 to 25. Counting the winning ones instead gives 14, and including pile 0 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
- An undirected graph has the vertices B, O, P, Q, T, V, Z and the edges Q–Z, Q–V, Q–T, P–Z, P–B, P–T, Z–O, Z–V, O–B. What is the size of a…
- A tree on the vertices C, F, I, R, V, X has the arcs C→R, V→C, I→V, V→X, F→V (each undirected edge is directed as shown). You may reverse…
- A directed acyclic graph has the vertices A, E, F, H, N, Q, R and the edges Q→N, Q→H, A→N, A→F, N→R, N→F, H→R, H→A, H→E. A topological…
- A directed acyclic graph has the vertices K, L, P, U, W, X, Y and the directed edges Y→W, Y→K, K→L, K→X, P→K, U→X, W→X, W→P, U→P, U→K…
- A tree has the vertices B, D, K, O, Q, V, W, Y, Z and the edges D–K, K–W, W–V, D–B, W–Q, V–Y, V–Z, Q–O. A set D dominates the tree if…
- Each cell of a grid with 3 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RDLLR UUDUR LDUDD From a cell you may…