集合幂级数少项式或卷积
给定
所求即是
套路地:我们求出所有
所求即是
考察
具体地,对于一个状态
考虑通过容斥将恰好变成容易处理的限制:也就是构造一个数组
考察
实际实现中需要扩域(将任意数写成
代码被封印在一台坏掉的电脑里了,有缘再补。
下面是代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int qpow(int a,int b){
if(b==0) return 1;
if(b==1) return a;
int res=qpow(a,b>>1);
res=res*res%mod;
if(b&1) res=res*a%mod;
return res;
}
#define ull unsigned long long
struct info{
ull a,na;
int b;
//a*0^b
//na=a^-1
info(int A=1,int B=0,int NA=1){
a=A,b=B,na=NA;
return ;
}
info operator*(const info &x)const{
return info(a*x.a%mod,b+x.b,na*x.na%mod);
}
info operator/(const info &x)const{
return info(a*x.na%mod,b-x.b,na*x.a%mod);
}
};
const int maxn = 2e4+114;
const int maxv = 1<<20;
int n,m,k;
int C[maxv];
int S[maxv];
info c1[maxv];
info ans[maxv];
int res[maxv];
int fac[maxv];
int inv[maxv];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int j=0;j<m;j++) cin>>C[1<<j]>>S[1<<j];
C[0]=1;
S[0]=0;
for(int j=0;j<m;j++){
for(int v=0;v<(1<<m);v++){
if((1<<j)&v) C[v]+=C[v-(1<<j)],S[v]|=S[v-(1<<j)];
}
}
for(int v=0;v<(1<<m);v++) C[v]%=mod;
fac[0]=(C[0]==0?1:C[0]);
for(int v=1;v<(1<<m);v++){
fac[v]=fac[v-1]*(C[v]==0?1:C[v])%mod;
}
inv[(1<<m)-1]=qpow(fac[(1<<m)-1],mod-2);
for(int v=(1<<m)-2;v>=0;v--){
inv[v]=inv[v+1]*(C[v+1]==0?1:C[v+1])%mod;
}
for(int v=0;v<(1<<m);v++){
if(C[v]==0) c1[v]=info(1,1,1);
else c1[v]=info(C[v],0,inv[v]*(v==0?1:fac[v-1])%mod);
}
for(int j=0;j<m;j++){
for(int v=0;v<(1<<m);v++){
if((1<<j)&v) c1[v]=c1[v]/c1[v-(1<<j)];
}
}
for(int v=0;v<(1<<m);v++){
ans[S[v]]=ans[S[v]]*c1[v];
}
for(int v=0;v<(1<<m);v++){
C[v]=S[v]=0;
}
}
for(int i=0;i<k;i++){
for(int v=0;v<(1<<k);v++){
if((1<<i)&v) ans[v]=ans[v]*ans[v-(1<<i)];
}
}
for(int v=0;v<(1<<k);v++){
if(ans[v].b>0) res[v]=0;
else res[v]=ans[v].a;
}
for(int i=0;i<k;i++){
for(int v=0;v<(1<<k);v++){
if((1<<i)&v) res[v]=(res[v]+mod-res[v-(1<<i)])%mod;
}
}
for(int v=0;v<(1<<k);v++) cout<<res[v]<<" ";
return 0;
}
/*
2 1 2
2 1
3 2
*/