A. Regular Bracket Sequences
题目大意
括号序列是仅包含字符“(”和“)”的字符串。常规方括号序列是一种方括号序列,可以通过在序列的原始字符之间插入字符“1”和“+”将其转换为正确的算术表达式。例如,括号序列“()”和“(())”是正则的(结果表达式是:”(1)+(1)”和“((1+1)+1)”),而“(”、“(”和“)”不是。
就是让你找出 n n n种长度为 2 n 2n 2n的不同的合法的括号对XD
题目解析
只让你输出n种情况就行,本蒟蒻将字符串拆分成个k个 “()” 的部分并且两边被n-k个 ‘(’ 与 ‘)’ 包住
比如以
n
=
4
n = 4
n=4为例:
()()()() k = 4
(()()()) k = 3
((()())) k = 2
(((()))) k = 1
循环输出结果即可
AC代码
#include <bits/stdc++.h>
// #include <b栈关注>
// #include <嘉然今天吃什么>
// #include <关注嘉然,顿顿解馋>
using namespace std;
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
constexpr int N = 1e5 + 100;
int main() {
io;
int T; cin >> T;
string s = "()";
while(T --) {
int n; cin >> n;
int k = 0;
for(int j = 0;j < n;j ++) {
for(int i = 0;i < k;i ++) {
cout << '(';
}
for(int i = 0;i < n-k;i ++) {
cout << s;
}
for(int i = 0;i < k;i ++) {
cout << ')';
}
cout << endl;
k ++;
}
}
return 0;
}