巨水,调了好久,心态爆炸
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
int n, m;
const int mod=9999973;
ll dp[105][105][105];
inline int qwq2(int x){
if(x<2) return 0;
return (x-1)*x/2;
}
int main(){
cin>>n>>m;
dp[1][0][0] = 1;
dp[1][1][0] = m;
dp[1][2][0] = qwq2(m);
for(int i=2; i<=n; i++)
for(int j=0; j<=m; j++)
for(int k=0; k<=m-j; k++){
ll &t=dp[i][j][k];
t = dp[i-1][j][k];
if(j>=1 && m-j-k+1>0) t = (t + dp[i-1][j-1][k] * (m-j-k+1) % mod) % mod;
if(k>=1) t = (t + dp[i-1][j+1][k-1] * (j + 1) % mod) % mod;
if(m-j-k+2>=2 && j>=2) t = (t + dp[i-1][j-2][k] * qwq2(m-j-k+2) % mod) % mod;
if(m-j-k+1 && j && k>=1) t = (t + dp[i-1][j][k-1] * j * (m-j-k+1) % mod) % mod;
if(k>=2) t = (t + dp[i-1][j+2][k-2]*qwq2(j+2)%mod)%mod;
}
int ans=0;
for(int i=0; i<=m; i++)
for(int k=0; k<=m-i; k++)
ans = (ans + dp[n][i][k]) % mod;
cout<<ans<<endl;
return 0;
}
原文地址:https://www.cnblogs.com/poorpool/p/8277817.html
时间: 2024-11-05 20:43:08