You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
610 B

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