大水题。显然限制就是同行同列个数不能超过2。
fi,j,k
表示前
i
行,放了
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105,MOD=9999973;
typedef long long LL;
int n,m;
LL f[maxn][maxn][maxn],ans;
int main(){
freopen("bzoj1801.in","r",stdin);
freopen("bzoj1801.out","w",stdout);
scanf("%d%d",&n,&m);
f[0][m][0]=1;
for(int i=0;i<=n-1;i++)
for(int j=0;j<=m;j++)
for(int k=0;j+k<=m;k++) if(f[i][j][k]){
(f[i+1][j][k]+=f[i][j][k])%=MOD;
if(j) (f[i+1][j-1][k+1]+=f[i][j][k]*j%MOD)%=MOD;
if(k) (f[i+1][j][k-1]+=f[i][j][k]*k%MOD)%=MOD;
if(j>=2) (f[i+1][j-2][k+2]+=f[i][j][k]*j*(j-1)/2%MOD)%=MOD;
if(k>=2) (f[i+1][j][k-2]+=f[i][j][k]*k*(k-1)/2%MOD)%=MOD;
if(j&&k) (f[i+1][j-1][k]+=f[i][j][k]*j*k%MOD)%=MOD;
}
for(int j=0;j<=m;j++)
for(int k=0;j+k<=m;k++) (ans+=f[n][j][k])%=MOD;
printf("%lld\n",ans);
return 0;
}