Problem C. 欧皇 ————2019.10.12
题目:
再次感激土蛋
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 typedef long long ll; 6 const ll mod = 1e9 + 7; 7 ll C[1005][1005]; 8 9 void pre(){ 10 C[0][0] = 1; 11 for(int i = 1; i <= 1000; i ++){ 12 C[i][0] = 1; 13 for(int j = 1; j <= i; j ++){ 14 C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; 15 } 16 } 17 } 18 int n, m, c; 19 int a[105]; 20 ll f[11][31][31]; 21 ll g[11][31][31], h[11][31][31]; 22 int main(){ 23 freopen("europe.in", "r", stdin); 24 freopen("europe.out", "w", stdout); 25 26 scanf("%d%d%d", &n, &m, &c); 27 for(int i = 1; i <= c; i ++){ 28 scanf("%d", &a[i]); 29 } 30 pre(); 31 for(int k = 1; k <= c; k ++){ 32 for(int i = 1; i <= n; i ++){ 33 for(int j = 1; j <= m; j ++){ 34 h[k][i][j] = C[i * j][a[k]]; 35 ll flag = -1; 36 for(int jj = j - 1; jj >= 1; jj --){ 37 h[k][i][j] = (h[k][i][j] + C[j][jj] * C[i * jj][a[k]] % mod * flag + mod) % mod; 38 flag = -flag; 39 } 40 } 41 } 42 } 43 for(int k = 1; k <= c; k ++){ 44 for(int j = 1; j <= m; j ++){ 45 for(int i = 1; i <= n; i ++){ 46 g[k][i][j] = h[k][i][j]; 47 // printf("%d %d %d %lld\n", k, i, j, g[k][i][j]); 48 ll flag = -1; 49 for(int ii = i - 1; ii >= 1; ii --){ 50 g[k][i][j] = (g[k][i][j] + C[i][ii] * h[k][ii][j] % mod * flag + mod) % mod; 51 flag = -flag; 52 } 53 // printf("%d %d %d %lld\n", k, i, j, g[k][i][j]); 54 } 55 } 56 } 57 f[0][0][0] = 1; 58 for(int k = 1; k <= c; k ++){ 59 for(int i = 1; i <= n; i ++){ 60 for(int j = 1; j <= m; j ++){ 61 for(int ii = 0; ii <= i - 1; ii ++){ 62 for(int jj = 0; jj <= j - 1; jj ++){ 63 if((i - ii) * (j - jj) < a[k]) continue; 64 f[k][i][j] = (f[k][i][j] + C[i][i - ii] * C[j][j - jj] % mod * f[k - 1][ii][jj] % mod * g[k][i - ii][j - jj]) % mod; 65 } 66 } 67 } 68 } 69 } 70 ll ans = 0; 71 for(int i = 1; i <= n; i ++){ 72 for(int j = 1; j <= m; j ++){ 73 ans = (ans + C[n][i] * C[m][j] % mod * f[c][i][j]) % mod; 74 } 75 } 76 //printf("%d %d %d\n", n, m, c); 77 printf("%lld\n", ans); 78 return 0; 79 }