比赛 EYOI暨SBOI暑假快乐赛5th 评测结果 AAATTTTTTT
题目名称 Famil Door and Brackets 最终得分 30
用户昵称 lihaoze 运行时间 14.025 s
代码语言 C++ 内存使用 12.04 MiB
提交时间 2022-06-29 10:52:50
显示代码纯文本
#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;
}