这是个DP 仔细想想其实不难
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 #include<vector> 9 #include<complex> 10 #define M 108 11 #define EPS 1e-10 12 #define MO 9999973 13 #define ll long long 14 #define inf 2000000000 15 #define E complex<double> 16 #define pi acos(-1) 17 using namespace std; 18 ll read() 19 { 20 char ch=getchar(); 21 ll x=0,f=1; 22 for(;ch<'0'||ch>'9';ch=getchar()) 23 if(ch=='-') 24 f=-1; 25 for(;ch>='0'&&ch<='9';ch=getchar()) 26 x=x*10+ch-'0'; 27 return x*f; 28 } 29 int n,m; 30 ll f[M][M][M]; 31 void jia(ll &a1,ll a2) 32 { 33 a1+=a2; 34 for(;a1>MO;a1-=MO); 35 } 36 int main() 37 { 38 n=read(); 39 m=read(); 40 f[0][0][0]=1; 41 for(int i=1;i<=n;i++) 42 for(int j=0;j<=m;j++) 43 for(int k=0;k<=m-j;k++) 44 { 45 f[i][j][k]=f[i-1][j][k]; 46 if(j) 47 jia(f[i][j][k],f[i-1][j-1][k]*(m-k-j+1)); 48 if(k) 49 jia(f[i][j][k],f[i-1][j+1][k-1]*(j+1)); 50 if(j>1) 51 jia(f[i][j][k],f[i-1][j-2][k]*(m-k-j+2)*(m-k-j+1)/2); 52 if(k) 53 jia(f[i][j][k],f[i-1][j][k-1]*(m-k-j+1)*j); 54 if(k>1) 55 jia(f[i][j][k],f[i-1][j+2][k-2]*(j+2)*(j+1)/2); 56 } 57 ll ans=0; 58 for(int i=0;i<=m;i++) 59 for(int j=0;j<=m-i;j++) 60 jia(ans,f[n][i][j]); 61 printf("%lld ",ans); 62 return 0; 63 }