#P2599. [ZJOI2009] 取石子游戏
[ZJOI2009] 取石子游戏
Description
After studying the Nim game and its variants, Orez discovered a brand-new stone-taking game, defined as follows:
There are piles of stones arranged in a row. Two players take turns. On each turn, a player may take any positive number of stones from either the leftmost pile or the rightmost pile; the entire pile may be taken, but taking zero stones is not allowed. The player who cannot move loses.
Orez asks: given any initial position, does there exist a winning strategy for the first player?
Input Format
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains an integer , the number of piles.
- The second line contains integers , where is the number of stones in the -th pile.
Output Format
For each test case, output a single integer or . Here, means there exists a winning strategy for the first player, and means there is not.
1
4
3 1 9 4
0
Hint
- For of the testdata, , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号