HDU ACM 3006 The Number of set (位运算)
http://acm.hdu.edu.cn/showproblem.php?pid=3006
1 #include <iostream> 2 using namespace std; 3 const int MAX = 0x0007fff; 4 int used[MAX] = {0}; 5 int main(){ 6 int n,m; 7 while(cin>>n>>m){ 8 m = 1<<m; 9 memset(used,0,sizeof(used)); 10 int i; 11 for(i=0;i<n;i++){ 12 int k; 13 cin>>k; 14 int j; 15 int ans = 0; 16 for(j=0;j<k;j++){ 17 int x; 18 cin>>x; 19 ans = ans | 1<<(x-1); 20 } 21 used[ans] = 1; 22 for(j=0;j<m;j++){ 23 if(used[j] == 1){ 24 used[j | ans] = 1; 25 } 26 } 27 } 28 29 int num = 0; 30 for(i=0;i<m;i++){ 31 if(used[i] == 1){ 32 num++; 33 } 34 } 35 cout<<num<<endl; 36 } 37 return 0; 38 }