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