设g[k][i][j]表示第k种颜色恰好占据了i行j列,即没有一行或一列是空的。
那么有
g[k][i][j] = C[i * j][cnt[k]] - ∑(g[k][x][y] * C[i][x] * C[j][y]),注意1 <= x <= i,1 <= y <= j,且(x, y)不能是(i, j)。
设f[k][i][j]表示前k种颜色恰好占据了i行j列。
那么有
f[k][i][j] = ∑(f[k - 1][x][y] * g[k][i - x][j - y] * C[i][x] * C[j][y]),注意0 <= x < i,0 <= y < j。
/* Pigonometry */
#include <cstdio>
#include <algorithm>
using namespace std;
typedef unsigned long long ULL;
const int maxn = 35, maxc = 12, maxm = 905;
const ULL p = 1000000009;
int n, m, c, cnt[maxc];
ULL g[maxc][maxn][maxn], f[maxc][maxn][maxn], C[maxm][maxm];
inline int iread() {
int f = 1, x = 0; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return f * x;
}
int main() {
n = iread(); m = iread(); c = iread();
for(int i = 1; i <= c; i++) cnt[i] = iread();
for(int i = 0; i < maxm; i++) {
C[i][0] = 1;
for(int j = 1; j <= i; j++) (C[i][j] = C[i - 1][j] + C[i - 1][j - 1]) %= p;
}
for(int k = 1; k <= c; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++)
if(i * j >= cnt[k] && max(i, j) <= cnt[k]) {
g[k][i][j] = C[i * j][cnt[k]];
for(int x = 1; x <= i; x++) for(int y = 1; y <= j; y++) if(!(x == i && y == j))
g[k][i][j] = (g[k][i][j] - C[i][x] * C[j][y] % p * g[k][x][y] % p + p) % p;
}
f[0][0][0] = 1;
for(int k = 1; k <= c; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(i * j >= cnt[k])
for(int x = 0; x < i; x++) for(int y = 0; y < j; y++)
(f[k][i][j] += f[k - 1][x][y] * g[k][i - x][j - y] % p * C[i][x] % p * C[j][y] % p) %= p;
ULL ans = 0;
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++)
(ans += f[c][i][j] * C[n][i] % p * C[m][j] % p) %= p;
printf("%llu\n", ans);
return 0;
}