luogu#P3480. [POI2009] KAM-Pebbles

[POI2009] KAM-Pebbles

题目描述

Johny and Margaret are playing "pebbles". Initially there is a certain number of pebbles on a table, grouped in nn piles. The piles are next to each other, forming a single row. The arrangement of stones satisfies an additional property that each pile consists of at least as many pebbles as the one to the left (with the obvious exception of the leftmost pile). The players alternately remove any number of pebbles from a single pile of their choice. They have to take care, though, not to make any pile smaller than the one left to it. In other words, the piles have to satisfy the initial property after the move as well. When one of the players cannot make a move (i.e. before his move there are no more pebbles on the table), he loses. Johny always starts, to compensate for Margaret's mastery in this game.

In fact Margaret is so good that she always makes the best move, and wins the game whenever she has a chance. Therefore Johny asks your help - he would like to know if he stands a chance of beating Margaret with a particular initial arrangement. Write a programme that determines answers to Johny's inquiries.

输入格式

In the first line of the standard input there is a single integer uu (1u101\le u\le 10) denoting the number of initial pebble arrangements to analyse.

The following 2u2u lines contain descriptions of these arrangements; each one takes exactly two lines.

The first line of each description contains a single integer nn, 1n10001\le n\le 1000 - the number of piles.

The second line of description holds non-negative integers separated by single spaces and denoting the numbers of pebbles in successive piles, left to right.

These numbers satisfy the following inequality a1a2ana_1\le a_2\le \cdots \le a_n.

The total number of pebbles in any arrangement does not exceed 10001000.

输出格式

Precisely nn lines should be printed out on the standard output.

The ii-th of these lines (for 1iu1\le i\le u) should hold the word TAK (yes in Polish), if Johny can win starting with the ii-th initial arrangement given in the input, or the word NIE (no in Polish), if Johny is bound to lose that game, assuming optimal play of Margaret.

题目大意

NN 堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数。两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏。问先手是否必胜。

输入格式

多组输入,第一行一个整数 uu 代表数据组数(1u101\le u\le 10

接下来共 2u2u 行,每两行代表一组数据:

第一行只有一个整数 nn1n10001\le n\le 1000),表示石子堆数;

第二行有 nn 个整数用空格隔开,第 ii 个整数 aia_i 表示第 ii 堆的石子个数,保证 a1a2a3ana_1\le a_2\le a_3\le \cdots\le a_n

对于每组数据,保证石子总数不超过 1000010000

输出格式

输出 uu 行,如果第 ii 组数据先手必胜,输出 TAK,否则输出 NIE

2
2
2 2
3
1 2 4

NIE
TAK