luogu#P3491. [POI 2009] SLW-Words

[POI 2009] SLW-Words

题目描述

Let hh be a function acting on strings composed of the digits 0 and 1. The function hh transforms the string ww by replacing (independently and concurrently) every digit 0 with 1 and every digit 1 with the string "10". For example h("1001")="101110"h("1001") = "101110", h("")=""h("") = "" (i.e. hh assigns an empty string to the empty string). Note that hh is an injection, or a one - to - one function. By hkh^k we denote the function hh composed with itself kk times. In particular, h0h^0 is the identity function h0(w)=wh^0(w)=w.

We are interested in the strings of the form hk("0")h^k("0") for k=0,1,2,3,k = 0,1,2,3,\cdots. This sequence begins with the following strings:

"0", "1", "10", "101", "10110", "10110101".

We call the string xx a substring of the string yy if it occurs in yy as a contiguous (i.e. one - block) subsequence. A sequence of integers k1,k2,,knk_1,k_2,\cdots,k_n is given. Your task is to check whether a string of the form $h^{k_1}("0") \cdot h^{k_2}("0") \cdots h^{k_n}("0")$ is a substring of hm("0")h^m("0") for some mm.

输入格式

The first line of the standard input contains a single integer tt, 1t131 \leq t \leq 13, denoting the number of test units. The first line of each test unit's description contains one integer nn, 1n1000001 \leq n \leq 100000. The second line of each description holds nn non - negative integers k1,k2,,knk_1,k_2,\cdots,k_n, separated by single spaces. The sum of the numbers in the second line of any test unit description does not exceed 10000000.

输出格式

Your programme should print out tt lines to the standard output, one for each test unit. Each line corresponding to a test unit should contain one word: TAK (yes in Polish - if $h^{k_1}("0") \cdot h^{k_2}("0") \cdots h^{k_n}("0")$ is a substring of hm("0")h^m("0") for some mm in that test unit, or NIE (no in Polish) otherwise.

题目大意

题目描述

函数 hh 作用于由数字 0011 组成的字符串,其通过将每一个数字 00 替换为 11,将每一个数字 11 替换为字符串 1010 来独立且同时地变换字符串 ww

例如:

h(1001")=101110"h(``1001")=``101110" h( ")= "h(``\ ")=``\ "

其中例二即把空字符串赋值给空字符串。

注意, hh 是一个一对一的函数。

我们用 hkh^k 表示函数 hh 使用 kk 次。

特别的, h0(w)=wh^0(w)=w

我们对 k=0,1,2,...k = 0, 1, 2, ...hk(0")h^k(``0") 形式的字符串感兴趣,这个序列为:

$$``0", ``1", ``10", ``101", ``10110", ``10110101", \ldots $$

如果字符串 xxyy 中以一个连续的(即一个块)子串出现,我们就称 xx 为字符串 yy 的子串。给出整数 k1,k2,k3,...,knk_1, k_2, k_3, ..., k_n 的序列。你的任务是检查是否有 mm ,使 $h^{k_1}(``0") \cdot h^{k_2}(``0") \cdot \ldots \cdot h^{k_n}(``0") $ 形式的字符串是 hm(0")h^m(``0") 的子串。

输入内容

输入的第一行包含一个整数 tt 表示样例数, 1t131 \leq t \leq 13。每个样例输入两行,一行 nn1n1000001 \leq n \leq 100000 ,另一行为 nn 个非负整数 k1,k2,k3,...,knk_1, k_2, k_3, ..., k_n ,用单个空格分隔。

输出内容

您的程序应该输出 tt 行,每个测试输出一行。如果存在 mm 使 $h^{k_1}(``0") \cdot h^{k_2}(``0") \cdot \ldots \cdot h^{k_n}(``0") $ 是 hm(0")h^m(``0") 的子串,就输出 TAK(波兰语中的 yes ),如果不存在 mm,则输出 NIE(波兰语中的 no )。

Translated By in_young_ren

2
2
1 2
2
2 0

TAK
NIE