#include<stdio.h>
int w2,n,p,q,w,a[2010],b[2010],ch[2010][6],w1,w0,same[2010],dif[2010],cnt2[2010];
long long dap,cnt,d0[2010],d1[2010],d[2010],dif0[2010],dif1[2010],dp[2010][2010];
int comb[2010][2010];
char x2,c[7];
long long comb2(int n,int r)
{
int i;
long long c=1;
for(i=r+1;i<=n;i++) c*=i, c%=1000000007;
return c;
}
int main()
{
int i,j,x;
scanf("%d %d %d",&n,&p,&q);
for(i=1;i<=n;i++){
scanf(" %c",&x2);
a[i]=x2-'a'+1;
}
for(i=1;i<=n;i++){
scanf(" %c",&x2);
b[i]=x2-'a'+1;
}
for(i=1;i<=n;i++){
scanf("%s",&c);
for(j=0;j<=4;j++){
if(c[j]!='.') ch[i][j+1]=1, cnt2[i]++;
}
}
for(i=1;i<=n;i++){
if(a[i]==b[i]) same[++w]=i;
else
{
if(ch[i][b[i]]) dif1[++w1]=cnt2[i]-2;
else dif0[++w2]=cnt2[i]-1;
}
}
dp[0][0]=1;
for(i=1;i<=w;i++){
x=same[i]; cnt=0;
for(j=1;j<=5;j++){
if(ch[x][j]) cnt++;
}
if(ch[x][a[x]]) dp[i][0]=dp[i-1][0]*(cnt-1);
else dp[i][0]=dp[i-1][0]*cnt;
for(j=1;j<=i;j++){
if(ch[x][a[x]]) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*(cnt-1);
else dp[i][j]=dp[i-1][j]*cnt;
dp[i][j]%=1000000007;
}
}
for(i=0;i<=w;i++) d[i]=dp[w][i];
for(i=1;i<=w0;i++)
{
dp[i][0]=dp[i-1][0]*dif0[i]; dp[i][0]%=1000000007;
for(j=1;j<=i;j++)
{
dp[i][j]=dp[i-1][j]*dif0[i]+dp[i-1][j-1];
dp[i][j]%=1000000007;
}
}
for(i=0;i<=w0;i++) d0[i]=dp[w0][i];
for(i=1;i<=w1;i++)
{
dp[i][0]=dp[i-1][0]*dif1[i]; dp[i][0]%=1000000007;
for(j=1;j<=i;j++)
{
dp[i][j]=dp[i-1][j]*dif1[i]+dp[i-1][j-1];
dp[i][j]%=1000000007;
}
}
for(i=0;i<=w1;i++) d1[i]=dp[w1][i];
comb[0][0]=1;
for(i=1;i<=w1;i++)
{
comb[i][0]=1;
for(j=1;j<=i;j++)
{
comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
comb[i][j]%=1000000007;
}
}
for(i=0;i<=p;i++)
{
for(j=0;j<=p-i;j++)
{
if(p+q-i*2-j>=0) dap+=d0[j]*d1[p+q-i*2-j]*(long long)comb[w1][p+q-i*2-j]*d[i];
dap%=1000000007;
}
}
printf("%lld",dap);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
48592 KB |
Output is correct |
2 |
Correct |
0 ms |
48592 KB |
Output is correct |
3 |
Incorrect |
0 ms |
48592 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
48592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
48592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |