Description
Alas! A set of D (1 <= d <= 15) diseases (numbered 1 .. d) is running through the farm. farmer John wowould like to milk as salary of his n (1 <=n <= 1,000) cows as possible. if the milked cows carry more than K (1 <= k <= d) Different diseases among them, then the milk will be too contaminated and will have to be discarded in its entirety. please help determine the largest number of cows FJ can milk without having to discard the milk. input
* Line 1: three space-separated integers: N, D, and K * lines 2 .. n + 1: line I + 1 describes the diseases of cow I with a list of 1 or more space-separated integers. the first integer, d_ I, is the count of cow I's diseases; the next d_ I integers enumerate the actual diseases. of course, the list is empty if d_ I is 0. there are nheaded cows, which may have d diseases. Now several heads are selected from these cows, but the number of diseased cows is less than K. output
* Line 1: m, the maximum number of cows which can be milked.
Question:
'2 ^ d': select the disease for enumeration and calculate the answer.
Code:
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring> //by zrt//problem:using namespace std;typedef long long LL;const int inf(0x3f3f3f3f);const double eps(1e-9);int n,m,k;int d[1005];inline bool judge(int x){ int c=0; while(x){ c++; x&=(x-1); } return c<=k;}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif scanf("%d%d%d",&n,&m,&k); for(int i=0,c;i<n;i++){ scanf("%d",&c); for(int j=0,x;j<c;j++){ scanf("%d",&x); d[i]|=1<<(x-1); } } int ans=0; for(int i=0;i<(1<<m);i++){ if(judge(i)){ int tot=0; for(int j=0;j<n;j++){ if((d[j]|i)==i) tot++; } ans=max(ans,tot); } } printf("%d\n",ans); return 0;}
Bzoj 1688: [usaco 2005 open] disease manangement disease management