DP
orz iwtwiioi
这种题居然是DP……原来统计方案数是可以用动态规划来做的啊= =用一些变量来维护一些信息,保证方案可行性/合法性
人太弱实在是有些忧伤……
1 /************************************************************** 2 Problem: 1037 3 User: Tunix 4 Language: C++ 5 Result: Accepted 6 Time:460 ms 7 Memory:42660 kb 8 ****************************************************************/ 9 10 //BZOJ 1037 11 #include<vector> 12 #include<cstdio> 13 #include<cstring> 14 #include<cstdlib> 15 #include<iostream> 16 #include<algorithm> 17 #define rep(i,n) for(int i=0;i<n;++i) 18 #define F(i,j,n) for(int i=j;i<=n;++i) 19 #define D(i,j,n) for(int i=j;i>=n;--i) 20 #define pb push_back 21 using namespace std; 22 inline int getint(){ 23 int v=0,sign=1; char ch=getchar(); 24 while(ch<'0'||ch>'9'){ if (ch=='-') sign=-1; ch=getchar();} 25 while(ch>='0'&&ch<='9'){ v=v*10+ch-'0'; ch=getchar();} 26 return v*sign; 27 } 28 const int N=155,INF=~0u>>2,MOD=12345678; 29 typedef long long LL; 30 /******************tamplate*********************/ 31 int n,m,k,f[N][N][21][21],ans; 32 int main(){ 33 #ifndef ONLINE_JUDGE 34 freopen("1037.in","r",stdin); 35 freopen("1037.out","w",stdout); 36 #endif 37 n=getint(); m=getint(); k=getint(); 38 f[0][0][0][0]=1; 39 F(i,0,n) F(j,0,m) F(k1,0,k) F(k2,0,k){ 40 if (k1+1<=k) (f[i+1][j][k1+1][max(k2-1,0)]+=f[i][j][k1][k2])%=MOD; 41 if (k2+1<=k) (f[i][j+1][max(k1-1,0)][k2+1]+=f[i][j][k1][k2])%=MOD; 42 } 43 F(x,0,k) F(y,0,k) (ans+=f[n][m][x][y])%=MOD; 44 printf("%d ",ans); 45 return 0; 46 }