HDU 3006 位运算

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;
const int maxn = 2e3+10;
const int mod = 2e9 + 7;
typedef long long ll;
typedef unsigned long long ull;

int n ,m, k, t;
int s[1<<14];

void work()
{
    memset(s,0,sizeof(s));
    for(int i = 0; i < n; i++){
        scanf("%d",&k);
        int w = 0;
        while(k--){
            scanf("%d",&t);
            w += 1<<(t - 1);//使用位运算,比如集合里有1,4,5,则w = 11001B
        }
        s[w] = 1;
        for(int i = 1; i < (1<<14); i++){
            if(s[i] == 1) //将新输入的集合与之前存在的集合合并
                s[w | i] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i < (1<<14); i++){
        if(s[i] == 1)
            ans++;
    }
    printf("%d\n",ans);
}

int main()
{
#ifdef LOCAL
    freopen("case.in","r",stdin);
    // freopen("case.out","w",stdout);
#endif
    while(scanf("%d%d",&n,&m) != EOF)
        work();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值