题解 P6076 【[JSOI2015]染色问题】
【题解】染色问题 [JSOI2015][P6076]
传送门:染色问题
【题目描述】
给出一个
【分析】
组合意义天地灭,代数推导保平安。 —— tiger0133
大家好像都是考虑容斥,咱这里有个不需要费脑子的二项式反演……(这句也是从别人的博客里嫖来的awa)
发现要统计的方案需满足条件“至少balabala”,不禁想到另一道题
但这里的
定义的“至少”真正含义为:钦定
正难则反,可以反过来设计状态:
由高维二项式反演可得:
则:
直接暴算复杂度
【Code】
#include<algorithm>
#include<cstring>
#include<cstdio>
#define LL long long
#define Re register int
using namespace std;
const int N=403,P=1e9+7;
int n,m,K,ans,Mi[N*N],jc[N],inv[N],invjc[N];
inline void in(Re &x){
int f=0;x=0;char ch=getchar();
while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=f?-x:x;
}
inline int C(Re m,Re n){return (LL)jc[n]*invjc[m]%P*invjc[n-m]%P;}
int main(){
// freopen("123.txt","r",stdin);
in(n),in(m),in(K),inv[1]=jc[0]=jc[1]=invjc[0]=invjc[1]=1;
for(Re i=2;i<=max(max(n,m),K);++i)inv[i]=(LL)inv[P%i]*(P-P/i)%P,jc[i]=(LL)jc[i-1]*i%P,invjc[i]=(LL)invjc[i-1]*inv[i]%P;
for(Re k=0;k<=K;++k){
Mi[0]=1;
for(Re i=1;i<=n*m;++i)Mi[i]=(LL)Mi[i-1]*(K-k+1)%P;
for(Re i=0;i<=n;++i)
for(Re j=0;j<=m;++j)
(ans+=(LL)((i+j+k&1)?P-1:1)*C(i,n)%P*C(j,m)%P*C(k,K)%P*Mi[(n-i)*(m-j)]%P)%=P;
}
printf("%d\n",ans);
}