Luogu

分析

考虑容斥。枚举 $i$ 行 $j$ 列不填、$k$ 种颜色不用。不难得到答案为

$$ \sum_{i=0}^n\sum_{j=0}^m\sum_{k=0}^c{n\choose i}{m\choose j}{c\choose k}(c-k+1)^{(n-i)(m-j)} $$

代码

// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;
 
inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=400+10;
const int mod=1e9+7;
inline int qpow(int a,int b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

int fac[N],ifac[N],pw[N*N];
inline void init(int n) {
    fac[0]=1;
    for (re int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);
    for (re int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod;
}
inline int C(int n,int m) {
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

int main() { init(400);
    int n=read(),m=read(),c=read(),ans=0;
    for (re int k=0;k<=c;++k) {
        for (re int i=pw[0]=1;i<=n*m;++i) pw[i]=1ll*pw[i-1]*(c-k+1)%mod;
        for (re int i=0;i<=n;++i)
            for (re int j=0;j<=m;++j) {
                int w=1ll*C(n,i)*C(m,j)%mod*C(c,k)%mod*pw[(n-i)*(m-j)]%mod;
                (i+j+k)&1?ans=(ans-w+mod)%mod:ans=(ans+w)%mod;
            }
    }
    printf("%d\n",ans);
    return 0;
}
最后修改:2020 年 02 月 27 日 10 : 37 AM