比赛 EYOI暨SBOI暑假快乐赛5th 评测结果 AAATTTTTTT
题目名称 Famil Door and Brackets 最终得分 30
用户昵称 ┭┮﹏┭┮ 运行时间 14.008 s
代码语言 C++ 内存使用 5.93 MiB
提交时间 2022-06-29 10:07:34
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,m,s; 
char a[100010],b[100010];
bool py(){
    int top = 0;
    for(int i = 1;i <= n;i++){
        if(b[i] == '(')top++;
        if(b[i] == ')'){
            if(top > 0)top--;
            else return 0;
        }
    }
    if(top == 0)return 1;
    else return 0;
}
void sou(int x){
    if(x == n+1){
        if(py()){
            //cout<<b+1<<endl;
            s++;
        }
        return;
    }
    if(b[x] == '?'){
        b[x] = '(';sou(x+1);b[x] = '?';
        b[x] = ')';sou(x+1);b[x] = '?';
    }
    else sou(x+1);
}
int main(){
    freopen("tribrackets.in","r",stdin);
    freopen("tribrackets.out","w",stdout);
    cin>>n>>m;
    if(n % 2 == 1){
        cout<<0<<endl;
        return 0;
    }
    scanf("%s",a+1);
    for(int i = 1;i <= m;i++)b[i] = a[i];
    if(n == m && py()){
        cout<<1<<endl;
        return 0;
    }
    for(int i = m+1;i <= n;i++)b[i] = '?';
    for(int i = 1;i <= n-m+1;i++){
        //cout<<b+1<<endl;
        sou(1);
        for(int j = i+m;j >= i;j--){
            b[j+1] = b[j];
        }
        b[i] = '?';
    }
    printf("%d\n",s);
    
    return 0;
}