本文共 1657 字,大约阅读时间需要 5 分钟。
数据量这么小,果断状态压缩+dp。
1 /* 3006 */ 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 #include 19 using namespace std;20 //#pragma comment(linker,"/STACK:102400000,1024000")21 22 #define mpii map 23 #define vi vector 24 #define pii pair 25 #define vpii vector >26 #define rep(i, a, n) for (int i=a;i =a;--i)28 #define pb push_back29 #define mp make_pair30 #define fir first31 #define sec second32 #define all(x) (x).begin(),(x).end()33 #define SZ(x) ((int)(x).size())34 #define lson l, mid, rt<<135 #define rson mid+1, r, rt<<1|136 37 const int N = 105;38 const int maxn = (2<<14)+1;39 bool visit[maxn];40 int sft[15];41 42 int main() {43 ios::sync_with_stdio(false);44 #ifndef ONLINE_JUDGE45 freopen("data.in", "r", stdin);46 freopen("data.out", "w", stdout);47 #endif48 49 int n, m;50 int x, nn;51 int ans, tmp;52 53 sft[1] = 1;54 rep(i, 2, 15)55 sft[i] = sft[i-1] << 1;56 57 memset(visit, false, sizeof(visit));58 while (scanf("%d %d", &n, &m)!=EOF) {59 memset(visit, false, sizeof(visit));60 visit[0] = true;61 rep(i, 0, n) {62 scanf("%d", &nn);63 tmp = 0;64 while (nn--) {65 scanf("%d", &x);66 tmp |= sft[x];67 }68 per(j, 0, maxn) {69 if (visit[j]) {70 visit[j|tmp] = true;71 }72 }73 }74 75 ans = 0;76 rep(j, 1, maxn)77 ans += visit[j];78 printf("%d\n", ans);79 }80 81 #ifndef ONLINE_JUDGE82 printf("time = %d.\n", (int)clock());83 #endif84 85 return 0;86 }
转载于:https://www.cnblogs.com/bombe1013/p/4606824.html