#include<bits/stdc++.h>#defineDEBUGfprintf(stderr,"Passing [%s] line %d\n", __FUNCTION__,__LINE__)#defineFile(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)#defineDCint T =gi<int>();while(T--)#definefifirst#definesesecond#definepbpush_back#definempmake_pairusingnamespace std;typedeflonglong LL;typedef pair <int,int> PII;typedef pair <int, PII> PIII;template<typenameT>inline T gi(){
T f =1, x =0;char c =getchar();while(c <'0'|| c >'9'){if(c =='-') f =-1; c =getchar();}while(c >='0'&& c <='9') x = x *10+ c -'0', c =getchar();return f * x;}constint INF =0x3f3f3f3f, N =503, M = N <<1, mod =1000000007;int n, K;int f[N][N], g[N][N], sum[N][N];char s[N];bool p[N][N];int mn[N];inlineboolCan(int pos,char c){return s[pos]== c || s[pos]=='?';}inlinevoidAdd(int&x,int y){x =(x + y)% mod;}intmain(){//File("");
n =gi<int>(), K =gi<int>();scanf("%s", s +1);memset(mn,0x3f,sizeof mn);for(int i =1; i <= n; i+=1)for(int j = i; j <=min(i + K -1, n); j+=1)if(Can(j,'*')) p[i][j]=true, mn[j]=min(mn[j], i);elsebreak;for(int len =2; len <= n; len+=1)for(int i =1; i + len -1<= n; i+=1){int j = i + len -1;
sum[i][j]= sum[i][j -1];if(!Can(i,'(')||!Can(j,')'))continue;if(len ==2){f[i][j]= g[i][j]=1;Add(sum[i][j], f[i][j]);continue;}if(p[i +1][j -1]) f[i][j]= g[i][j]=1;for(int k = i; k < j; k+=1)Add(g[i][j],1ll* f[i][k]* g[k +1][j]% mod);for(int l = i +1; l < j; l+=1)if(mn[l]!=0x3f3f3f3f){int tmp =max(mn[l], i +1);Add(g[i][j],1ll* g[l +1][j]*((sum[i][l -1]+ mod - sum[i][tmp -2])% mod)% mod);}Add(f[i][j], g[i +1][j -1]),Add(g[i][j], g[i +1][j -1]);for(int k = i +1; k <=min(i + K, j -2); k+=1)if(p[i +1][k])Add(f[i][j], g[k +1][j -1]),Add(g[i][j], g[k +1][j -1]);elsebreak;for(int k =max(i +2, j - K); k < j; k+=1)if(p[k][j -1])Add(f[i][j], g[i +1][k -1]),Add(g[i][j], g[i +1][k -1]);Add(sum[i][j], f[i][j]);}printf("%d\n", g[1][n]);return0;}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· 不到万不得已,千万不要去外包
· C# WebAPI 插件热插拔(持续更新中)
· .NET 9 new features-C#13新的锁类型和语义
· 会议真的有必要吗?我们产品开发9年了,但从来没开过会
· 《SpringBoot》EasyExcel实现百万数据的导入导出
2019-10-24 题解【BZOJ4145】「AMPPZ2014」The Prices