Data Structures & AlgorithmsHardGATE CS · ICPC regional
A pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 2, 4} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 19 is the position a LOSS for the player to move?
- A. 7
- B. 5
- C. 6
- D. 13
Correct answer: C. 6
Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 6 losing piles in 1 to 19. Counting the winning ones instead gives 13, and including pile 0 gives 7.
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 F, J, K, M, S, T, V, X and the edges J–V, J–X, J–F, J–M, J–K, V–F, V–S, X–F, X–M, X–K, F–K, S–M. What…
- An undirected graph has the vertices A, J, K, L, O, Q, X, Y and the edges J–Q, J–Y, J–A, J–O, Q–L, Q–X, K–L, K–O. What is the size of a…
- An undirected graph has the vertices C, E, H, K, M, N, T, Y and the edges E–M, E–N, E–Y, E–T, C–N, C–H, C–Y, C–T, M–N, M–K, N–K, Y–T. What…
- An undirected graph has the vertices C, F, J, O, U, V, W, X, Z and the edges Z–O, Z–U, Z–C, F–U, F–J, O–J, O–V, O–W, U–W, U–X, U–C, V–W…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G... G... G... Each step, which is a…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): U–A (27), Y–M (6), I–Y (29), U–M (21), A–M…