#P7938. 「Wdcfr-1」Beautiful Array
「Wdcfr-1」Beautiful Array
题目描述
In this problem, we define a sequence of (
and )
as a "bracket sequence".
The definition of Regular Bracket Sequence is as follows:
()
is a Regular Bracket Sequence.- If
A
is a Regular Bracket Sequence, then(A)
is also a Regular Bracket Sequence. - If
A
andB
are Regular Bracket Sequences, thenAB
is also a Regular Bracket Sequence.
For example: ()
, (())
, and ()()
are all Regular Bracket Sequences, but )(
, ()(
are not.
In particular, an empty sequence is not a Regular Bracket Sequence sequence in this problem.
Now cute Ran gives you a bracket sequence of length . She wants you to construct strictly increasing arrays. Let us denote them as
(you can leave any of them empty). You need to ensure that all integers between appear exactly once in these arrays.
An array is Beautiful if is a Regular Bracket Sequence.
Ran wonders whether it is possible to construct these arrays so that at least of the arrays are "beautiful arrays".
输入格式
Each test contains multiple test cases.
The first line contains an integer , the number of test cases.
For each test case, the first line contains two integers and , and the second line contains a bracket sequence .
输出格式
For each test case, print one line.
If it is possible to construct these arrays, print . Otherwise print .
题目大意
定义一个字符串为括号串当且仅当其仅由 (
和 )
组成。
试将一个长度为 的括号串分为 个子序列,子序列可以为空,且每个字符都必须分到恰好一个子序列中,使得至少 个子序列为匹配的括号串。空序列不算匹配的括号序列。无解请输出 ,否则输出 。本题多组数据,其中数据组数为 。
定义 为 的子序列当且仅当 能由 在顺序不改变的前提下删除若干元素后得到。
*样例 解释:你可以将第一个和第二个字符分入第一个子序列,让第二个子序列为空子序列。此时第一个子序列为 ()
,第二个为空,总计有一个匹配的括号序列,满足要求。
2
2 1
()
2 99
()
1
0
提示
Explanation
For the first test case, we can construct and . So is a "beautiful array".
For the second test case, it is obvious that we cannot use two numbers to construct beautiful arrays.
Constraints
.