Bzoj 1688: [usaco 2005 open] disease manangement disease management

Source: Internet
Author: User
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

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.