【HDOJ】3006 The Number of set

位运算标记状态。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 
 5 #define MAXN 15
 6 
 7 bool visit[1<<MAXN];
 8 
 9 int main() {
10     int n, m;
11     int i, j, k, v;
12     int ans;
13     
14 #ifndef ONLINE_JUDGE
15     freopen("data.in", "r", stdin);
16 #endif
17     
18     while (scanf("%d %d", &n, &m) != EOF) {
19         memset(visit, false, sizeof(visit));
20         while (n--) {
21             scanf("%d", &k);
22             v = 0;
23             while (k--) {
24                 scanf("%d", &j);
25                 v |= 1<<(j-1);
26             }
27             visit[v] = true;
28             for (i=1; i<(1<<m); ++i) {
29                 if (visit[i]) {
30                     visit[i|v] = true;
31                 }
32             }
33         }
34         ans = 0;
35         for (i=1; i<(1<<m); ++i)
36             if (visit[i])
37                 ++ans;
38         printf("%d\n", ans);
39     }
40 
41     return 0;
42 }

 

posted on 2014-12-13 20:06  Bombe  阅读(127)  评论(0编辑  收藏  举报

导航