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, 4} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 20 is the position a LOSS for the player to move?
- A. 13
- B. 7
- C. 6
- D. 8
Correct answer: B. 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 20. Counting the winning ones instead gives 13, 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 connected undirected graph has the vertices B, F, K, N, U, W and weighted edges (weights in brackets): F–U (13), F–N (4), N–U (17), B–W…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): Y–K (11), S–K (2), Q–D (10), D–K (14), Y–S…
- A tree has vertices with values in brackets: N[-2], J[9], M[1], R[0], H[9], G[6], S[-2]. The edges are N–J, J–M, N–R, M–H, N–G, J–S. A…
- A directed acyclic graph has the vertices A, H, N, Q, X, Z and the edges N→Z, H→Z, A→H, Q→H, Q→Z, Q→X. A topological order lists every…
- An undirected graph has the vertices A, B, D, P, R, Y and the edges P–D, P–B, P–R, D–A, D–Y, B–Y, A–R, R–Y. In how many ways can each…
- Each cell of a grid with 3 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RURUR LRDLU RDDRD From a cell you may…