Bacteria (disease) (bitwise operations) (state compression)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.