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

35 lines
668 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}