Bacteria (disease)
Time limit: 1 Sec memory limit: up to MB
Submissions: 9 resolution: 5
Submitted State [Discussion Version]
Title Description
Recently, D (1≤d≤15) species of bacteria have appeared on the farm. John will choose as much milk as possible from his N (1≤n≤1000) head cows, but if the selected cows carry more than K (1≤k≤d) of different bacteria, the milk produced will fail. Please help John figure out how many cows you can choose.
Input
Line 1th: three integer n,d,k.
The following n lines: line I represents the bacteria carried by a cow. The first integer, Di, indicates the number of bacterial species carried by the cow, followed by a Di integer indicating the respective species of the bacteria.
Output
A number of M, the maximum number of selectable cows.
Sample input
6 3 201 11 21 32 2 12 2 1
Sample output
5
Tips
Sample Description: Select l,2,3,5,6 head cows, only # and two kinds of bacteria.
"Analysis" look at the other people's solution, the first time to see this approach, bit operation, very diao look.
#include <iostream>#include<cstring>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<time.h>#include<string>#include<map>#include<stack>#include<vector>#include<Set>#include<queue>#defineINF 0x3f3f3f3f#defineMoD 1000000007typedefLong Longll;using namespacestd;Const intn=33010;intn,k,d,m,t;inta[n],cnt[33000];intFunintx) { intC=0; while(x) {if(x&1) c++;x>>=1; }returnC;}intMain () {memset (A,0,sizeof(a)); memset (CNT,0,sizeof(CNT)); CIN>>n>>d>>k;intans=0; for(intI=0; i<n;i++) {cin>>T; for(intj=0; j<t;j++) {cin>>m; A[i]+=pow (2, M-1); } } for(intI=0; I<=pow (2, d); i++) { if(Fun (i) >k)Continue; for(intj=0; j<n;j++) { if((I|a[j]) ==i) cnt[i]++; } ans=Max (ans,cnt[i]); } cout<<ans<<Endl; return 0;}
View Code
Bacteria (disease) (bitwise operations) (state compression)