题解:P12232 集合幂级数求逆

· · 题解

可能讲了一些比较基础的部分,如果您水平比较高可以跳过一些内容。

记 f_s 为 [x^s]F(x),g_s 为 [x^s]G(x)。

根据 F(x)G(x)=1,显然有

\sum_{i \subseteq s} f_i g_{s-i}=[s=\varnothing] $。 所以有 $g_{\varnothing}=\frac{1}{f_{\varnothing}}$,$g_s=-\frac{1}{f_{\varnothing}} \sum_{i \subsetneq s}f_ig_{s-i}$($s \neq \varnothing$)。 然后类似子集卷积模板,我们定义 $f(i,s)=f(s) \times [|s|=i]$,$[x^s]F(i,x)$ 为 $f(i,s)$。 考虑依次枚举集合大小 $i$,对于 $G(x)$ 中已经求出的部分和 $F(x)$,我们先保留其进行了 FWT 变换的形式,然后计算答案时枚举转移点的集合大小 $j$,加上 $G(j,x)$ 和 $F(i-j,x)$ 对 $G(i,x)$ 的贡献,注意还要乘上 $-\frac{1}{f_{\varnothing}}$ 的贡献。 时间复杂度 $O(n^22^n)$。 ## Code ```cpp #include<bits/stdc++.h> namespace fast_IO{ #define IOSIZE 100000 char ibuf[IOSIZE], obuf[IOSIZE], *p1 = ibuf, *p2 = ibuf, *p3 = obuf; #define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++)) #define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x) #define isdigit(ch) (ch>47&&ch<58) #define isspace(ch) (ch<33) template<typename T> inline T read() { T s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s * w; } template<typename T> inline bool read(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; } template<typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + 48); } inline bool read(char &s) { while (s = getchar(), isspace(s)); return true; } inline bool read(char *s) { char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) *s++ = ch, ch = getchar(); *s = '\000'; return true; } inline void print(char x) { putchar(x); } inline void print(char *x) { while (*x) putchar(*x++); } inline void print(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); } inline bool read(std::string& s) { s = ""; char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) s += ch, ch = getchar(); return true; } inline void print(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); } inline bool read(bool &b) { char ch; while(ch=getchar(), isspace(ch)); b=ch^48; return true; } inline void print(bool b) { putchar(b+48); } template<typename T, typename... T1> inline int read(T& a, T1&... other) { return read(a) + read(other...); } template<typename T, typename... T1> inline void print(T a, T1... other) { print(a), print(other...); } struct Fast_IO { ~Fast_IO() { fwrite(obuf, p3 - obuf, 1, stdout); } } io; template<typename T> Fast_IO& operator >> (Fast_IO &io, T &b) { return read(b), io; } template<typename T> Fast_IO& operator << (Fast_IO &io, T b) { return print(b), io; } #define cout io #define cin io }using namespace fast_IO; using namespace std; const int mod=998244353; int n; vector<int>f[21],g[21]; #define pop __builtin_popcount #define pb emplace_back inline int add(int a,int b){return ((a+=b)>=mod)?(a-mod):a;} inline int norm(int a,int b){return ((a-=b)<0)?(a+mod):a;} inline int qpow(int a,int b){ int res=1; while(b){ if(b&1)res=1ll*res*a%mod; a=1ll*a*a%mod; b>>=1; } return res; } inline void OR(int limit,vector<int>&a,int opt){ for(int len=2;len<=limit;len<<=1){ for(int i=0;i<limit;i+=len) for(int j=i+(len>>1);j<i+len;++j) a[j]=add(1ll*a[j-(len>>1)]*opt%mod,a[j]); } } inline void fwt(vector<int>&a){OR(a.size(),a,1);} inline void ifwt(vector<int>&a){OR(a.size(),a,mod-1);} signed main(){ cin>>n; int limit=(1<<n); for(int i=0;i<=n;++i)f[i].resize(limit),g[i].resize(limit); for(int i=0;i<limit;++i)cin>>f[pop(i)][i]; g[0][0]=qpow(f[0][0],mod-2); int z=mod-g[0][0]; fwt(g[0]); for(int i=0;i<=n;++i)fwt(f[i]); for(int i=1;i<=n;++i){ for(int j=0;j<i;++j){ for(int s=0;s<limit;++s) g[i][s]=add(g[i][s],1ll*g[j][s]*f[i-j][s]%mod); } ifwt(g[i]); for(int s=0;s<limit;++s)g[i][s]=1ll*g[i][s]*z%mod; fwt(g[i]); } for(int i=0;i<=n;++i)ifwt(g[i]); for(int i=0;i<limit;++i)cout<<g[pop(i)][i]<<" "; cout<<"\n"; return 0; } ```