正文
增加 79 行删除 0 行
206 行未改动全部展开207208209210206 行未改动全部展开return 0;}```:::206 行未改动全部展开207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289206 行未改动全部展开return 0;}```:::## 子集反演和超级反演### 子集反演公式如果我们已知子集和数组 $f$,想反推出原数组 $a$,这就是子集反演:$$a_{\mathrm{mask}} = \sum_{s \subseteq \mathrm{mask}} (-1) ^ {|\mathrm{mask}| - |s|} f_s$$其中 $|x|$ 表示 $x$ 的二进制中的 $1$ 的个数。### 逆 SOS DP和正向 SOS DP 相对称,改为$$a_{\mathrm{mask}} = a_{\mathrm{mask}} - a_{\mathrm{mask} \oplus 2 ^ k} ~~ (\mathrm{mask} ~ \texttt{含第} ~ i ~ \texttt{位时})$$### 超集反演公式$$a_{\mathrm{mask}} = \sum_{s \supseteq \mathrm{mask}} (-1) ^ {|\mathrm{mask}| - |s|} f_s$$## 练习### CodeChef - COVERING Covering Sets$$R(X) = \sum_{X \subseteq A \cup B \cup C} F(A) G(B) H(C)$$$$Ans = \sum_{A, B, C} F(A) G(B) H(C) \cdot 2 ^ {|A \cup B \cup C|}$$设 $\displaystyle F_a(S) = \sum_{A \subseteq S} F(A)$,$\displaystyle G_b(S) = \sum_{B \subseteq S} G(B)$,$\displaystyle H_c(S) = \sum_{C \subseteq S} H(C)$。构造 $W(S) = F_a(S) G_b(S) H_C(S)$,其表示$$\sum_{A \cup B \cup C \subseteq S} F(A) G(B) H(C)$$而我们要求恰好相等的,所以可以利用 SOS DP 逆变换求出答案。:::success[代码]```cpp#include <bits/stdc++.h>using namespace std;using LL = long long;const int N = 1 << 20, M = 1e9 + 7;LL n, m, a[3][N], f[N];LL Pow(LL x, LL y) {LL s = 1;for (; y; x = x * x % M, y >>= 1) y & 1 && (s = s * x % M);return s;}int main() {cin.tie(0)->sync_with_stdio(0);cin >> n, m = (1 << n);for (int i = 0; i < 3; i++) {for (int j = 0; j < m; j++) cin >> a[i][j];}for (int i = 0; i < 3; i++) {for (int j = 0; j < n; j++) {for (int s = 0; s < m; s++) {(s >> j) & 1 && (a[i][s] = (a[i][s] + a[i][s ^ (1 << j)]) % M);}}}for (int s = 0; s < m; s++) {f[s] = a[0][s] * a[1][s] % M * a[2][s] % M;}for (int i = 0; i < n; i++) {for (int s = 0; s < m; s++) {(s >> i) & 1 && (f[s] = (f[s] - f[s ^ (1 << i)] + M) % M);}}LL ans = 0;for (int i = 0; i < m; i++) {ans = (ans + f[i] * Pow(2, __builtin_popcount(i)) % M) % M;}cout << ans;return 0;}```:::