# [容斥] Codeforces 449D Jzzhu and Numbers

## 题解

$$S$$ 是所有二进制位的集合，$$g(T)$$ 表示按位与后至少在 $$T$$ 中的二进制位上为 $$1$$ 的子序列的个数，则有

$ans=(2^n-1)-\sum_{T\subseteq S\land T\neq\emptyset}(-1)^{|T|-1} g(T)$

## 题解

#include <bits/stdc++.h>
using namespace std;

#define LL long long

template<typename elemType>
elemType X = 0, w = 0; char ch = 0;
while (!isdigit(ch)) { w |= ch == '-';ch = getchar(); }
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
T = (w ? -X : X);
}

const LL MOD = 1e9 + 7;
const int m = 20;
int f[1 << 20], pow2[(1 << 20) + 1];
int n;

int main() {
for (int i = 1;i <= n;++i) { int x; Read(x); ++f[x]; }
pow2[0] = 1;
for (int i = 1;i <= (1 << m);++i) {
pow2[i] = pow2[i - 1] << 1;
if (pow2[i] > MOD) pow2[i] -= MOD;
}
for (int i = 0;i < m;++i)
for (int j = 0;j < (1 << m);++j)
if (!(j & (1 << i))) f[j] = (f[j] + f[j ^ (1 << i)]) % MOD;
for (int i = 0;i < (1 << m);++i) {
f[i] = (pow2[f[i]] - 1);
if (f[i] < 0) f[i] += MOD;
}
for (int i = 0;i < m;++i) {
for (int j = 0;j < (1 << m);++j) {
if (j & (1 << i)) {
f[j] -= f[j ^ (1 << i)];
if (f[j] < 0) f[j] += MOD;
}
}
}
LL ans = pow2[n] - 1 + (f[(1 << m) - 1] - f[0]);
ans = (ans % MOD + MOD) % MOD;
printf("%I64d\n", ans);

return 0;
}

posted @ 2022-01-12 16:13  AE酱  阅读(51)  评论(0编辑  收藏  举报