【无标题】

Mihai plans to watch a movie. He only likes palindromic movies, so he wants to skip some (possibly zero) scenes to make the remaining parts of the movie palindromic.

You are given a list s of n non-empty strings of length at most 3, representing the scenes of Mihai's movie.

A subsequence of s is called awesome if it is non-empty and the concatenation of the strings in the subsequence, in order, is a palindrome.

Can you help Mihai check if there is at least one awesome subsequence of s?

A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

A sequence a is a non-empty subsequence of a non-empty sequence b if a can be obtained from b by deletion of several (possibly zero, but not all) elements.

输入:
The first line of the input contains a single integer t (1≤t≤100) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer n (1≤n≤105) — the number of scenes in the movie.

Then follows n lines, the i-th of which containing a single non-empty string si of length at most 3, consisting of lowercase Latin letters.

It is guaranteed that the sum of n over all test cases does not exceed 105.

输出:
For each test case, print "YES" if there is an awesome subsequence of s, or "NO" otherwise (case insensitive).

样例输入:
6
5
zx
ab
cc
zx
ba
2
ab
bad
4
co
def
orc
es
3
a
b
c
3
ab
cd
cba
2
ab
ab
复制
样例输出:
YES
NO
NO
YES
YES
NO
复制
注释:
In the first test case, an awesome subsequence of s is [ab,cc,ba]

翻译:

米海计划看一部电影。他只喜欢回文电影,所以他想跳过一些(可能零)场景,使电影的其余部分回文。
你会得到一个由n个长度不超过3的非空字符串组成的列表,代表米海电影的场景。
如果s的子序列是非空的,且子序列中的字符串按顺序连接为回文,则称其为awesome。
你能帮Mihai看看是否有至少一个很棒的s子序列吗?
回文是一个前后读相同的字符串,例如字符串“z”、“aaa”、“aba”、“abccba”是回文,而字符串“codeforces”、“reality”、“ab”则不是。
如果可以通过删除几个(可能是零,但不是全部)元素从b中获得A,则序列A是非空序列b的非空子序列。
输入:
输入的第一行包含一个整数t(1≤T≤100)-测试用例的数量。测试用例的描述如下。
每个测试用例的第一行包含一个整数n(1)≤N≤105)-电影中的场景数量。
然后是n行,第i行包含一个长度不超过3的非空字符串si,由小写拉丁字母组成。
保证所有测试用例中n的总和不超过105。
输出:
对于每个测试用例,如果有令人敬畏的子序列,则打印“是”,否则打印“否”(不区分大小写)。

样例输入:

6
5
zx
ab
cc
zx
ba
2
ab
bad
4
co
def
orc
es
3
a
b
c
3
ab
cd
cba
2
ab
ab

复制

样例输出:

YES
NO
NO
YES
YES
NO

注释:
在第一个测试用例中,s的一个可怕的子序列是[ab,cc,ba]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值