CF2233C.Cost of a Bracket Sequence
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let the cost of an arbitrary bracket string be the length of it's longest subsequence∗ that is a regular bracket sequence†.
You are given a bracket string s and an integer k. Your task is to remove at most k characters from the string s so that the cost of the resulting string is minimized.
∗A sequence a is a subsequence of a sequence b if a can be obtained from b by the deletion of several (possibly, zero or all) element from arbitrary positions.
†A bracket sequence is called regular if it is possible to obtain a correct arithmetic expression by inserting the characters + and 1 into this sequence. For example, the sequences "(())()", "()", and "(()(()))" are regular, while ")(", "(()", and "(()))(" — are not.
定义任意括号串的代价为:其最长子序列(∗)的长度,该子序列本身是一个合法括号序列(†)。
给定一个括号串 s 和一个整数 k。你的任务是从字符串 s 中最多删除 k 个字符,使得所得字符串的代价最小化。
∗ 序列 a 是序列 b 的子序列,当且仅当 a 可通过从 b 中任意位置删除若干个(可能为零个或全部)元素而得到。
† 若能在该括号序列中插入字符 + 和 1,从而得到一个合法的算术表达式,则称该括号序列是合法的。例如,串 "(())()"、"()" 和 "(()(()))" 是合法的;而 ")("、"(()" 和 "(()))(" 则不是。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤n≤5000; 0≤k≤n) — the length of the string s and the maximum number of deletions.
The second line of each test case contains a string s of length n consisting of the characters "(" and/or ")".
Additional input constraints:
- the sum of n over all test cases does not exceed 5000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤103)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤5000;0≤k≤n)——分别表示字符串 s 的长度以及最多允许的删除次数。
每个测试用例的第二行包含一个长度为 n 的字符串 s,其仅由字符 "(" 和/或 ")" 组成。
附加输入约束:
- 所有测试用例的 n 值之和不超过 5000。
输出格式
For each test case, output a binary string of length n. The i-th character should be equal to "1" if the corresponding character of the string s is removed, and "0" otherwise.
The number of ones in the string must not exceed k. The cost of the string obtained after removing the marked characters must be as small as possible.
If there are several answers, output any of them.
对于每个测试用例,输出一个长度为 n 的二进制字符串。其中第 i 个字符应为 "1",当且仅当字符串 s 中对应位置的字符被删除;否则为 "0"。
该二进制字符串中 "1" 的个数不得超过 k。在删除被标记为 "1" 的字符后所得字符串的代价须尽可能小。
若存在多个满足条件的答案,输出任意一个即可。
输入输出样例
输入#1
10 2 1 )( 2 0 () 4 1 (()) 4 1 ())( 5 1 ((()) 6 2 ()()() 6 2 (()()) 6 2 ())(() 7 3 (()((() 10 3 (()())())(
输出#1
00 00 1000 1000 00010 101000 001001 100001 1100001 0101001000
说明/提示
In the first test case, the cost of the string is already 0, so it is possible not to delete anything.
In the third test case, it is impossible to obtain a string of cost 0 after one deletion, but it is possible to obtain a string of cost 2 by deleting any character.
在第一个测试用例中,字符串的代价已经是 0,因此可以不删除任何字符。
在第三个测试用例中,经过一次删除操作后无法得到代价为 0 的字符串,但通过删除任意一个字符,可以得到代价为 2 的字符串。
输入解题思路,AI测评打分。不知道怎么写?