CF1574A.Regular Bracket Sequences
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
You are given an integer n. Your goal is to construct and print exactly n different regular bracket sequences of length 2n.
括号序列是指仅由字符 ( 和 ) 组成的字符串。正则括号序列(regular bracket sequence)是一种括号序列,它可以通过在原序列的字符之间插入字符 1 和 +,从而转化为一个合法的算术表达式。例如,括号序列 "()()" 和 "(())" 是正则的(对应的表达式分别为 "(1)+(1)" 和 "((1+1)+1)"),而 ")(", "(" 和 ")" 则不是。
给你一个整数 n。你的目标是构造并输出恰好 n 个互不相同的长度为 2n 的正则括号序列。
输入格式
The first line contains one integer t (1≤t≤50) — the number of test cases.
Each test case consists of one line containing one integer n (1≤n≤50).
第一行包含一个整数 t(1≤t≤50)—— 测试用例的数量。
每个测试用例由一行组成,该行包含一个整数 n(1≤n≤50)。
输出格式
For each test case, print n lines, each containing a regular bracket sequence of length exactly 2n. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.
对于每个测试用例,输出 n 行,每行包含一个长度恰好为 2n 的合法括号序列。你在该测试用例中输出的所有括号序列必须互不相同(但在不同测试用例之间可以重复)。若存在多种答案,输出任意一种即可。可以证明,这样的答案总是存在的。
输入输出样例
输入#1
3 3 1 3
输出#1
()()() ((())) (()()) () ((())) (())() ()(())
输入解题思路,AI测评打分。不知道怎么写?