把横的和竖的分开考虑
//#pragma comment(linker, "/STACK:102400000,102400000") #include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<cmath> #include<cassert> #include<cstring> #include<iomanip> using namespace std; #ifdef _WIN32 #define i64 __int64 #define out64 "%I64d\n" #define in64 "%I64d" #else #define i64 long long #define out64 "%lld\n" #define in64 "%lld" #endif /************ for topcoder by zz1215 *******************/ #define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) #define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++) #define FF(i,a) for( int i = 0 ; i < (a) ; i ++) #define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --) #define S64(a) scanf(in64,&a) #define SS(a) scanf("%d",&a) #define LL(a) ((a)<<1) #define RR(a) (((a)<<1)+1) #define pb push_back #define pf push_front #define X first #define Y second #define CL(Q) while(!Q.empty())Q.pop() #define MM(name,what) memset(name,what,sizeof(name)) #define MC(a,b) memcpy(a,b,sizeof(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define read freopen("in.txt","r",stdin) #define write freope("out.txt","w",stdout) const int inf = 0x3f3f3f3f; const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL; const double oo = 10e9; const double eps = 10e-9; const double pi = acos(-1.0); const int maxn = 1010; const int mod = 9999991; int c[maxn][maxn]; int dpx[maxn][maxn]; int dpy[maxn][maxn]; int sx[maxn]; int sy[maxn]; void init() { MM(c,0); for(int i=0;i<maxn;i++) { c[i][0]=1; c[i][i]=1; } for(int i=1;i<maxn;i++) { for(int j=1;j<i;j++) { c[i][j] = c[i-1][j-1]+c[i-1][j]; c[i][j] %= mod; } } } int T,n,m,k,x00,y00; bool inx(int x) { return x>=1 && x<=m; } bool iny(int y) { return y>=1 && y<=n; } int start() { for(int i=1;i<=n;i++) { for(int j=0;j<=k;j++) { dpy[i][j] = 0; } } for(int i=1;i<=m;i++) { for(int j=0;j<=k;j++) { dpx[i][j] = 0; } } dpy[x00][0] = 1; dpx[y00][0] = 1; int to; for(int i=1;i<=k;i++) { for(int now=1;now<=n;now++) { for(int u=-2;u<=2;u++) { if(u==0) continue; to = now+u; if( iny(to) ) { dpy[to][i] += dpy[now][i-1]; dpy[to][i] %= mod; } } } } for(int i=1;i<=k;i++) { for(int now = 1;now<=m;now++) { for(int u=-2;u<=2;u++) { if(u==0) continue; to = now+u; if(inx(to)) { dpx[to][i] += dpx[now][i-1]; dpx[to][i] %= mod; } } } } MM(sx,0); MM(sy,0); for(int i=0;i<=k;i++) { for(int j=1;j<=n;j++) { sy[i] += dpy[j][i]; sy[i] %= mod; } } for(int i=0;i<=k;i++) { for(int j=1;j<=m;j++) { sx[i] += dpx[j][i]; sx[i] %= mod; } } i64 temp; int ans=0; for(int i=0;i<=k;i++) { temp = c[k][i]; temp *= sx[i]; temp %=mod; temp *= sy[k-i]; temp%=mod; ans+=temp; ans%=mod; } return ans; } int main() { init(); cin>>T; for(int tt=1;tt<=T;tt++) { cin>>n>>m>>k>>x00>>y00; cout<<"Case #"<<tt<<":"<<endl; cout<<start()<<endl; } return 0; }
hdu 4832 百度之星初赛二B
时间: 2024-10-27 06:51:34