同BZOJ1801。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mod 999983 using namespace std; long long n,m,dp[105][105][105]; long long calc(long long x) {return (x*(x-1)/2)%mod;} int main() { scanf("%lld%lld",&n,&m); dp[0][0][0]=1; for (long long i=1;i<=n;i++) for (long long j=0;j<=m;j++) for (long long k=0;k<=m-j;k++) { dp[i][j][k]+=dp[i-1][j][k];dp[i][j][k]%=mod; if (j) dp[i][j][k]+=dp[i-1][j-1][k]*(m-j-k+1)%mod;dp[i][j][k]%=mod; if ((k) && (j<=m-1)) dp[i][j][k]+=dp[i-1][j+1][k-1]*(j+1)%mod;dp[i][j][k]%=mod; if (j>=2) dp[i][j][k]+=dp[i-1][j-2][k]*calc(m-j-k+2)%mod;dp[i][j][k]%=mod; if (k) dp[i][j][k]+=dp[i-1][j][k-1]*(j*(m-j-k+1)%mod)%mod;dp[i][j][k]%=mod; if ((k>=2) && (j<=m-2)) dp[i][j][k]+=dp[i-1][j+2][k-2]*calc(j+2)%mod; } long long ans=0; for (int i=0;i<=m;i++) for (int j=0;j<=m-i;j++) ans=(ans+dp[n][i][j])%mod; printf("%lld\n",ans); return 0; }