比赛 |
EYOI暨SBOI暑假快乐赛5th |
评测结果 |
AAAEEEEEEE |
题目名称 |
Famil Door and Brackets |
最终得分 |
30 |
用户昵称 |
HeSn |
运行时间 |
2.157 s |
代码语言 |
C++ |
内存使用 |
15.91 MiB |
提交时间 |
2022-06-29 11:15:25 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, m, ans = 0;
string s;
int dfs2(int x, int c, string s2) {
if(x > c) {
int kh = 0, f = 1;
for(int i = 0; i < s2.length(); i ++) {
if(s2[i] == ')' && kh == 0) {
f = 0;
break;
}
if(s2[i] == ')') {
kh --;
}
if(s2[i] == '(') {
kh ++;
}
}
if(kh == 0 && f == 1) {
ans ++;
}
return 0;
}
dfs2(x + 1, c, s2 + ")");
dfs2(x + 1, c, s2 + "(");
return 0;
}
int dfs(int x, int c, string s1) {
if(x > c) {
return 0;
}
dfs2(1, c - x, s1 + s);
dfs(x + 1, c, s1 + "(");
dfs(x + 1, c, s1 + ")");
return 0;
}
int main() {
freopen("tribrackets.in", "r", stdin);
freopen("tribrackets.out", "w", stdout);
cin >> n >> m >> s;
dfs(0, n - m, "");
if(n == m) {
cout << 1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}