Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
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 ≤ 25 is the position a LOSS for the player to move?
- A. 11
- B. 14
- C. 13
- D. 12
Correct answer: A. 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
- A directed graph has the vertices E, H, L, M, Q, U and the arcs H→U, M→Q, U→H, U→Q, E→H, E→M, L→H. How many strongly connected components…
- A directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. Count the directed…
- Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A connected undirected graph has the vertices D, L, Q, R, T, Y and the edges Y–D, Y–T, D–Q, D–R, D–L, R–T, R–L, T–L. Parallel edges are…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, with edges P4–Q2, P3–Q3, P4–Q3, P1–Q3, P2–Q1, P4–Q1. What is the…