LuoGu: CF449D Jzzhu and Numbers
CF: D. Jzzhu and Numbers
使得与和为一个数,需要所有数都含有这个数,而不能有多的位。对于一个数,考虑其超集,在超集中选择任意的数,一定与和是这个数的超集,除非不选,则共有 $2 ^ s - 1$ 中方案。考虑容斥,需要排除多的位,再将超集的答案减去即可。
查看代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <cstdio> using namespace std; typedef long long LL; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; flag && (x = ~x + 1); } template <class Type> void write(Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar(x % 10 + '0'); } const int N = 20, mod = 1e9 + 7; int n, f[1 << N]; int binpow(int b, int k) { int res = 1; while (k) { k & 1 && (res = (LL)res * b % mod); b = (LL)b * b % mod; k >>= 1; } return res; } int main() { read(n); for (int a; n; n--) read(a), f[a]++; for (int i = 0; i < N; i++) for (int j = 0; j < 1 << N; j++) j >> i & 1 && ((f[j ^ 1 << i] += f[j]) %= mod); for (int i = 0; i < 1 << N; i++) f[i] = binpow(2, f[i]) - 1; for (int i = 0; i < N; i++) for (int j = 0; j < 1 << N; j++) j >> i & 1 && ((f[j ^ 1 << i] -= f[j]) %= mod); write((f[0] + mod) % mod); return 0; }
|