BZOJ 1801 [Ahoi2009]chess 中国象棋

题解:DP一下

每一行为阶段

发现只有3种本质不同的列,即已经放了0,1,2三个棋子的列

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mm=9999973;
const int maxn=109;

int n,m;
int f[maxn][maxn][maxn];
int ans;
long long C[maxn][maxn];

int main(){
	scanf("%d%d",&n,&m);
	C[0][0]=1;
	for(int i=1;i<=100;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mm;
		}
	}
	
	f[1][m][0]=1;
	f[1][m-1][1]=m;
	f[1][m-2][2]=m*(m-1)/2;
	
	for(int i=1;i<n;++i){
		for(int a=0;a<=m;++a){
			for(int b=0;a+b<=m;++b){
				int c=m-a-b;
				f[i+1][a][b]=(f[i+1][a][b]+f[i][a][b])%mm;
				if(a)f[i+1][a-1][b+1]=(f[i+1][a-1][b+1]+f[i][a][b]*a)%mm;
				if(b)f[i+1][a][b-1]=(f[i+1][a][b-1]+f[i][a][b]*b)%mm;
				if(a>=2)f[i+1][a-2][b+2]=(f[i+1][a-2][b+2]+f[i][a][b]*C[a][2])%mm;
				if(a&&b)f[i+1][a-1][b]=(f[i+1][a-1][b]+f[i][a][b]*a*1LL*b)%mm;
				if(b>=2)f[i+1][a][b-2]=(f[i+1][a][b-2]+f[i][a][b]*C[b][2])%mm;
			}
		}
	}
	for(int a=0;a<=m;++a){
		for(int b=0;a+b<=m;++b){
			ans=(ans+f[n][a][b])%mm;
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

  

 

posted @ 2018-02-20 11:47  ws_zzy  阅读(124)  评论(0编辑  收藏  举报