Integer Game
Time limit5sMemory limit256 MB
Players alternately remove a number with no larger remaining neighbor from a row permutation, and whoever takes 1 wins, so decide the winner under optimal play.
- Level
Hard8 of 10
- Topics
- Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
Alice and Bob place squares in a row and play a game. Each square holds one of the numbers through , and no number appears twice.
Alice starts, and the two players alternate turns. On a turn a player removes one number. A player may remove the number on a square only if neither square sharing an edge with it, that is the square immediately to its left and the square immediately to its right, holds a larger number. A square whose number is already removed is empty and does not block the removal, and the outside of the row does not block it either. Once a number is removed its square holds no number.
The player who removes wins the game. Given the initial state, write a program that determines who wins when both players play optimally.
Input
The first line contains the number of test cases ().
The first line of each test case contains (). The second line contains the initial state of the game, from the leftmost square to the rightmost square. These numbers are a permutation that uses each of through once.
Output
For each test case, print the name of the winner on its own line. Print Alice if Alice wins, and print Bob if Bob wins.