luogu#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:

  1. () is a Regular Bracket Sequence.
  2. If A is a Regular Bracket Sequence, then (A) is also a Regular Bracket Sequence.
  3. If A and B are Regular Bracket Sequences, then AB 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 ss of length nn. She wants you to construct 2m2\cdot m strictly increasing arrays. Let us denote them as p1,p2,,p2mp_1,p_2,\cdots,p_{2 m} (you can leave any of them empty). You need to ensure that all integers between 1n1\sim n appear exactly once in these arrays.

An array pi={r1,r2,,rk}p_i=\{r_1,r_2,\cdots,r_k\} is Beautiful if {sr1,sr2,,srk}\{s_{r_1},s_{r_2},\cdots,s_{r_k}\} is a Regular Bracket Sequence.

Ran wonders whether it is possible to construct these arrays so that at least mm of the 2m2\cdot m arrays are "beautiful arrays".

输入格式

Each test contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, the first line contains two integers nn and mm, and the second line contains a bracket sequence ss.

输出格式

For each test case, print one line.

If it is possible to construct these arrays, print 11. Otherwise print 00.

题目大意

定义一个字符串为括号串当且仅当其仅由 () 组成。

试将一个长度为 nn 的括号串分为 2m2m 个子序列,子序列可以为空,且每个字符都必须分到恰好一个子序列中,使得至少 mm 个子序列为匹配的括号串。空序列不算匹配的括号序列。无解请输出 00,否则输出 11。本题多组数据,其中数据组数为 TT

定义 AABB 的子序列当且仅当 AA 能由 BB 在顺序不改变的前提下删除若干元素后得到。

*样例 11 解释:你可以将第一个和第二个字符分入第一个子序列,让第二个子序列为空子序列。此时第一个子序列为 (),第二个为空,总计有一个匹配的括号序列,满足要求。

2
2 1
()
2 99
()
1
0

提示

Explanation

For the first test case, we can construct p1={1,2}p_1=\{1,2\} and p2={} p_2=\{\}. So p1p_1 is a "beautiful array".

For the second test case, it is obvious that we cannot use two numbers to construct 9999 beautiful arrays.

Constraints

1T,n,m2001\le T,n,m\le 200.