Files
python/TangDou/LanQiaoBei/LanQiaoSTEMA202008/DaKuoHao_3.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

31 lines
610 B
C++

#include <bits/stdc++.h>
using namespace std;
int n;
int res;
stack<char> stk;
bool check(string t) {
stack<char>().swap(stk);
for (int i = t.size() - 1; i >= 0; i--) {
if (!stk.empty() && stk.top() == '}' && t[i] == '{')
stk.pop();
else
stk.push(t[i]);
}
return stk.size() == 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;
}