位运算标记状态。
1 #include2 #include 3 #include 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< i) { 29 if (visit[i]) { 30 visit[i|v] = true; 31 } 32 } 33 } 34 ans = 0; 35 for (i=1; i<(1< i) 36 if (visit[i]) 37 ++ans; 38 printf("%d ", ans); 39 } 40 41 return 0; 42 }