You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
554 B

#include <bits/stdc++.h>
using namespace std;
int n;
int res;
void dfs(int u, string t) {
if (u == 2 * n + 1) {
if (t.size() == 0) res++;
return;
}
//当前填充{
dfs(u + 1, t + "{");
if (t.back() == '{') //如果t的最后一个字符是 {
t.pop_back(), dfs(u + 1, t); //当前填充},就会对掉一对{}
// t.substr(0,t.size()-1) 去掉尾巴
else
dfs(u + 1, t + "}");
}
int main() {
cin >> n;
dfs(1, "");
cout << res << endl;
return 0;
}