显示代码纯文本
#include <bits/stdc++.h>
using i64 = long long;
const int N = 1e5+10;
int n, m;
i64 ans = 0;
std::string s, ts;
bool valid(std::string S) {
int x = 0;
for (int i = 0; i < n; ++ i) {
if (S[i] == '(') ++ x;
else {
if (x == 0) return false;
else -- x;
}
}
return x == 0;
}
void dfs(int idx) {
if (idx == n - 1) return void(ans += valid(ts));
auto& t = ts[idx];
if (t == '0') {
t = '(', dfs(idx + 1);
t = ')', dfs(idx + 1);
t = '0';
} else {
dfs(idx + 1);
}
}
int main() {
freopen("tribrackets.in", "r", stdin);
freopen("tribrackets.out", "w", stdout);
std::cin >> n >> m >> s;
for (int i = 0; i <= n - m; ++ i) {
#define str(x, y) std::string(x, y)
ts = str(i, '0') + s + str(n - m - i, '0');
dfs(0);
}
std::cout << (ans % static_cast<i64>(1e9 + 7)) << '\n';
return 0;
}