'commit'
This commit is contained in:
35
TangDou/LanQiaoBei/LanQiaoSTEMA202008/DaKuoHao_2.cpp
Normal file
35
TangDou/LanQiaoBei/LanQiaoSTEMA202008/DaKuoHao_2.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user