35 lines
668 B
C++
35 lines
668 B
C++
#include <bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
const int N = 1e5 + 10;
|
||
|
||
int n;
|
||
int res;
|
||
|
||
char stk[N];
|
||
bool check(string s) {
|
||
int tt = 0; // 因为是多次使用栈,所以这里tt需要每次清空为0
|
||
for (int i = s.size() - 1; i >= 0; i--) {
|
||
if (tt && stk[tt] == '}' && s[i] == '{')
|
||
tt--;
|
||
else
|
||
stk[++tt] = s[i];
|
||
}
|
||
return tt == 0;
|
||
}
|
||
|
||
void dfs(int u, string t) {
|
||
if (u == 2 * n + 1) {
|
||
if (check(t)) res++;
|
||
return;
|
||
}
|
||
|
||
dfs(u + 1, t + "{");
|
||
dfs(u + 1, t + "}");
|
||
}
|
||
int main() {
|
||
cin >> n;
|
||
dfs(1, "");
|
||
cout << res << endl;
|
||
return 0;
|
||
} |