P6442 [COCI2011-2012#6] KOŠARE
与 CF449D Jzzhu and Numbers 很相似。
查看代码
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; 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, M = 1 << N, mod = 1e9 + 7; int n, m, p[M], f[M]; int main () { read(n), read(m); p[0] = 1; for (int i = 1; i <= n; i++) p[i] = (p[i - 1] << 1) % mod; for (int k; n; n--) { read(k); int s = 0; for (int a; k; k--) { read(a); s |= 1 << a - 1; } f[s]++; } for (int i = 0; i < m; i++) for (int j = 0; j < 1 << m; j++) j >> i & 1 && (f[j] += f[j ^ 1 << i]); for (int i = 0; i < 1 << m; i++) f[i] = p[f[i]] - 1; for (int i = 0; i < m; i++) for (int j = 0; j < 1 << m; j++) j >> i & 1 && ((f[j] -= f[j ^ 1 << i]) %= mod); write((f[(1 << m) - 1] + mod) % mod); return 0; }
|