P2051-中国象棋
1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 #define _rep(i,a,b) for(int i = (a);i > b;i --) 4 #define INF 0x3f3f3f3f 5 #define MOD 9999973 6 typedef long long ll; 7 using namespace std; 8 inline ll read() 9 { 10 ll ans = 0; 11 char ch = getchar(), last = ' '; 12 while(!isdigit(ch)) last = ch, ch = getchar(); 13 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 14 if(last == '-') ans = -ans; 15 return ans; 16 } 17 inline void write(ll x) 18 { 19 if(x < 0) x = -x, putchar('-'); 20 if(x >= 10) write(x / 10); 21 putchar(x % 10 + '0'); 22 } 23 int N,M; 24 ll dp[103][103][103]; 25 inline ll C2(ll n) 26 { 27 return ((n*(n-1))/2) % MOD; 28 } 29 int main() 30 { 31 N = read(), M = read(); 32 dp[0][0][0] = 1; 33 _for(i,1,N+1) 34 _for(j,0,M+1) 35 _for(k,0,M-j+1) 36 { 37 ll &t = dp[i][j][k]; 38 t = dp[i-1][j][k]; 39 if(k>=1) 40 t += dp[i-1][j+1][k-1]*(j+1); 41 t %= MOD; 42 if(j>=1) 43 t += dp[i-1][j-1][k]*(M-j-k+1); 44 t %= MOD; 45 if(k>=2) 46 t += dp[i-1][j+2][k-2]*C2(j+2); 47 t %= MOD; 48 if(k>=1) 49 t += dp[i-1][j][k-1]*j*(M-j-k+1); 50 t %= MOD; 51 if(j>=2) 52 t += dp[i-1][j-2][k]*C2(M-k-j+2); 53 t %= MOD; 54 } 55 56 ll rnt = 0; 57 _for(i,0,M+1) 58 _for(j,0,M+1) 59 rnt += dp[N][i][j],rnt %= MOD; 60 printf("%lld\n",rnt); 61 return 0; 62 }