Alice and Bob play the following game:
1) First they choose a permutation of the first N numbers.
2) They play alternately, and Alice plays first.
3) In turn, they can remove any remaining number from the permutation.
4) The game ends when the remaining numbers form an increasing sequence. The person who played the last move (after which the sequence increases) wins the game.
Assuming both games are optimal, who wins the game?
Input: The first line contains the number of test cases. Each case contains an integer N in the first line, followed by a permutation of the integers 1..N in the second line.
Conclusion: T output lines, one for each test case, containing βAliceβ if Alice wins the game and βBobβ otherwise.
Input Example:
2
3
1 3 2
5
5 3 2 1 4
Output result:
Alice
Bean
Limitations:
1 <= T <= 100
2 <= N <= 15
The permutation at first will not be incremental.
I am trying to solve the above problem. I got to the end, but I was stuck at some point. Please help me continue.
In the above problem for a permutation of length 2, player 1 always wins.
For a permutation of length 3, player 2 wins if the string strictly increases or decreases.
For a permutation of length 4, if player 1 can force the string to strictly increase or decrease by removing the character, it wins 2 more players.
The conclusion follows:
If the current player can make the line strictly increasing, he wins. (Trivial case)
If he / she can do it strictly, the winner is determined by the number of elements in this sequence. If there are an even number of elements in this sequence, the current player loses, but wins.
But what if the resulting row does not increase or decrease?