poj2436

位操作枚举

View Code
#include <iostream>
#include
<cstdlib>
#include
<cstring>
#include
<cstdio>
using namespace std;

#define maxn 1005

int n, d, k;
int cow[maxn];

bool ok(int a)
{
int ret = 0;
while (a)
{
ret
+= (a & 1);
a
>>= 1;
}
return ret == k;
}

int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d%d", &n, &d, &k);
for (int i = 0; i < n; i++)
{
int a, b;
scanf(
"%d", &a);
for (int j = 0; j < a; j++)
{
scanf(
"%d", &b);
cow[i]
|= (1 << (b - 1));
}
}
int s = (1 << k) - 1;
int e = s << (d - k);
int ans = 0;
for (int i = s; i <= e; i++)
if (ok(i))
{
int temp = 0;
for (int j = 0; j < n; j++)
if ((cow[j] & i) == cow[j])
temp
++;
ans
= max(ans, temp);
}
printf(
"%d\n", ans);
return 0;
}
原文地址:https://www.cnblogs.com/rainydays/p/2168703.html