标签:des style blog http color java os io
2 2 2 1 1 1 2 2 2 1 1
Case #1: 2 Case #2: 4
/* *********************************************** Author :rabbit Created Time :2014/8/15 13:55:51 File Name :111.cpp ************************************************ */ #pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include <stdlib.h> #include <string.h> #include <limits.h> #include <string> #include <time.h> #include <math.h> #include <queue> #include <stack> #include <set> #include <map> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; const ll mod=9999991; ll dpx[1010][1010],dpy[1010][1010],sumx[1010],sumy[1010],C[1010][1010]; int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int T; memset(C,0,sizeof(C)); for(int i=1;i<=1000;i++){ C[i][0]=C[i][i]=1; for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } cin>>T; for(int t=1;t<=T;t++){ int N,M,K,x,y; cin>>N>>M>>K>>x>>y; memset(dpx,0,sizeof(dpx)); memset(dpy,0,sizeof(dpy)); memset(sumx,0,sizeof(sumx)); memset(sumy,0,sizeof(sumy)); dpx[0][x]=1; dpy[0][y]=1; for(int i=1;i<=K;i++) for(int j=1;j<=N;j++) for(int k=-2;k<=2;k++){ if(k==0)continue; int t=j+k; if(t<1||t>N)continue; dpx[i][t]=(dpx[i][t]+dpx[i-1][j])%mod; } for(int i=1;i<=K;i++) for(int j=1;j<=M;j++) for(int k=-2;k<=2;k++){ if(!k)continue; int t=j+k; if(t<1||t>M)continue; dpy[i][t]=(dpy[i][t]+dpy[i-1][j])%mod; } for(int i=0;i<=K;i++) for(int j=1;j<=N;j++) sumx[i]=(dpx[i][j]+sumx[i])%mod; for(int i=0;i<=K;i++) for(int j=1;j<=M;j++) sumy[i]=(sumy[i]+dpy[i][j])%mod; ll ans=0; for(int i=0;i<=K;i++){ ll tt=1; tt=(tt*C[K][i])%mod; tt=(tt*sumx[i])%mod; tt=(tt*sumy[K-i])%mod; ans=(ans+tt)%mod; } printf("Case #%d:\n",t); cout<<ans<<endl; } return 0; }
HDU 4832 组合计数dp,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://blog.csdn.net/xianxingwuguan1/article/details/38584515