状压个啥$qwq$
思路:大力$DP$
提交:2次(自信的开了$int$)
题解:(见注释)
#include<cstdio> #include<iostream> using namespace std; #define ull unsigned long long #define ll long long #define R register ll #define pause (for(R i=1;i<=10000000000;++i)) #define In freopen("NOIPAK++.in","r",stdin) #define Out freopen("out.out","w",stdout) namespace Fread { static char B[1<<15],*S=B,*D=B; #ifndef JACK #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++) #endif inline int g() { R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix; if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix; } inline bool isempty(const char& ch) {return (ch<=36||ch>=127);} inline void gs(char* s) { register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar())); } } using Fread::g; using Fread::gs; const int N=110,M=9999973; int n,m,ans; ll f[N][N][N]; //f[i][j][k]:所处行编号i,含有一个棋子的列数j,含有两个棋子的列数k signed main() { n=g(),m=g(); f[0][0][0]=1; for(R i=1;i<=n;++i) for(R j=0;j<=m;++j) for(R k=0;k<=m-j;++k){ f[i][j][k]+=f[i-1][j][k]; //不填棋子 if(j>=1) f[i][j][k]+=f[i-1][j-1][k]*(m-k-j+1); //选空列填一个棋子 if(k>=1) f[i][j][k]+=f[i-1][j+1][k-1]*(j+1); //选含有一个棋子的某列 if(j>=2) f[i][j][k]+=f[i-1][j-2][k]*(m-k-j+2)*(m-k-j+1)/2; //选两个空列分别填一个棋子 if(k>=1) f[i][j][k]+=f[i-1][j][k-1]*(m-k-j+1)*j; //选一个空列和含有一个棋子的某列分别填一个棋子 if(k>=2) f[i][j][k]+=f[i-1][j+2][k-2]*(j+2)*(j+1)/2; //选含有一个棋子的某两列分别填一个棋子 f[i][j][k]%=M; } for(R j=0;j<=m;++j) for(R k=0;k<=m-j;++k) ans=(ans+f[n][j][k])%M; printf("%d\n",ans); }
2019.07.17