/*
设 f[i][j] 表示前 i 个,cnt[(]-cnt[)] 的数量为 j 的方案数。
这个可以做出 P,Q 的样子啊。
接下来枚举 P 的长度,lp+lq+ls=n
然后枚举 P 的 cnt[(]-cnt[)] 的值。
需要满足 dertap+dertaq+dertas=0
直接乘法原理即可。
比如枚举出 p[lp][dertap],那么 lq=n-ls-lp, dertaq=-dertas-dertap
*/
#include <bits/stdc++.h>
#define int long long
#define rep(i,l,r) for(i=l;i<=r;++i)
using namespace std;
const int N=100005,p=1e9+7;
int f[2015][2015];
char str[N];
int i,j,x,mrex=p,n,m,ret;
inline void pre()
{
f[0][0]=1;
rep(i,1,2005)
{
f[i][0]=f[i-1][1];
rep(j,1,i)f[i][j]=(f[i-1][j-1]+f[i-1][j+1])%p;//,printf("%d %d %d\n",i,j,f[i][j]);
}
return ;
}
inline int gmax()
{
rep(i,1,m)
{
if(str[i]=='(')++x;else --x;
mrex=min(mrex,x);
}
return mrex;
}
inline int solve()
{
pre();
gmax();
// if(n>2000)printf("%d %d\n",x,mrex);
rep(i,0,n-m)
rep(j,0,i)
{
if(j>=-mrex && j+x<=n-m-i)
{
// printf("%d %d %d %d %d %d\n",i,j,f[i][j],n-m-i,j+x,f[n-m-i][j+x]);
(ret+=(1ll*f[i][j]*f[n-m-i][j+x])%p)%=p;
}
// printf("%d %d %d\n", i, j, ret);
}
printf("%lld",ret);
return 0;
}
signed main()
{
scanf("%d %d %s", &n, &m, str+1);
solve();
return 0;
}
1426C - Increase and Copy | 520C - DNA Alignment |
767A - Snacktower | 1365A - Matrix Game |
714B - Filya and Homework | 31A - Worms Evolution |
1691A - Beat The Odds | 433B - Kuriyama Mirai's Stones |
892A - Greed | 32A - Reconnaissance |
1236D - Alice and the Doll | 1207B - Square Filling |
1676D - X-Sum | 1679A - AvtoBus |
1549A - Gregor and Cryptography | 918C - The Monster |
4B - Before an Exam | 545B - Equidistant String |
1244C - The Football Season | 1696B - NIT Destroys the Universe |
1674A - Number Transformation | 1244E - Minimizing Difference |
1688A - Cirno's Perfect Bitmasks Classroom | 219A - k-String |
952A - Quirky Quantifiers | 451B - Sort the Array |
1505H - L BREAK into program | 171E - MYSTERIOUS LANGUAGE |
630D - Hexagons | 1690D - Black and White Stripe |