显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,m,f[2005][2005]={0},cnt=0x3f3f3f3f,cur=0,ans=0;
int mod=1000000007;
string s;
int main(){
freopen("tribrackets.in","r",stdin);
freopen("tribrackets.out","w",stdout);
cin>>n>>m;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='(')cur++;
if(s[i]==')')cur--;
cnt=min(cnt,cur);
}
f[0][0]=1;
for(int i=1;i<=n-m;i++)
{
for(int j=0;j<=i;j++)
{
f[i][j]=(f[i-1][j-1]+f[i-1][j+1])%mod;
}
}
for(int i=0;i<=n-m;i++)
{
for(int j=max(-cnt,0);j+cur<=n-m-i&&j<=i;j++)
{
ans=(ans+1ll*f[i][j]*f[n-m-i][j+cur]%mod)%mod;
}
}
cout<<ans%mod<<endl;
return 0;
}