标签:
2 2 2 1 1 1 2 2 2 1 1
Case #1: 2 Case #2: 4
#include<stdio.h> #include<string.h> #define mod 9999991 int c[1010][1010],row[2][1010],cnt[2][1010],col[2][1010]; void fun() { int i,j; for(i=0;i<1010;i++) c[i][0]=1; for(i=1;i<1010;i++) { for(j=1;j<1010;j++) { c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; } } } int main() { int t,cot=0; scanf("%d",&t); fun(); while(t--) { int n,m,k,x,y,i,j; scanf("%d%d%d%d%d",&n,&m,&k,&x,&y); memset(col,0,sizeof(col)); memset(row,0,sizeof(row)); memset(cnt,0,sizeof(cnt)); int cur=0; col[0][y]=row[0][x]=cnt[0][0]=cnt[1][0]=1; for(i=1;i<=k;i++) { cur^=1; memset(col[cur],0,sizeof(col[cur])); memset(row[cur],0,sizeof(row[cur])); for(j=1;j<=m;j++) { if(j-2>=1) col[cur][j]=(col[cur][j]+col[cur^1][j-2])%mod; if(j-1>=1) col[cur][j]=(col[cur][j]+col[cur^1][j-1])%mod; if(j+1<=m) col[cur][j]=(col[cur][j]+col[cur^1][j+1])%mod; if(j+2<=m) col[cur][j]=(col[cur][j]+col[cur^1][j+2])%mod; cnt[0][i]=(cnt[0][i]+col[cur][j])%mod; // printf("________%d %d %d\n",cnt[0][i],i,col[cur][j]); } for(j=1;j<=n;j++) { if(j-2>=1) row[cur][j]=(row[cur][j]+row[cur^1][j-2])%mod; if(j-1>=1) row[cur][j]=(row[cur][j]+row[cur^1][j-1])%mod; if(j+1<=n) row[cur][j]=(row[cur][j]+row[cur^1][j+1])%mod; if(j+2<=n) row[cur][j]=(row[cur][j]+row[cur^1][j+2])%mod; cnt[1][i]=(cnt[1][i]+row[cur][j])%mod; } } __int64 ans=0; printf("Case #%d:\n",++cot); for(i=0;i<=k;i++) { // printf("%d %d %d\n",cnt[0][i],cnt[1][k-i],c[k][i]); ans=(ans+(((__int64)cnt[0][i]*cnt[1][k-i])%mod)*c[k][i]%mod)%mod; } printf("%I64d\n",ans); } }
标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/46136985