POJ 2436 Usaco Silver

Source: Internet
Author: User

Test instructions

A total of 15 diseases

There are n cows, each of which has a di disease, which is indicated by a number between 1-15.

Require the choice of the most cattle to make their disease species not more than K

Ideas:

Enumeration state, status is the current disease, and then determine whether each cow can choose to

Code

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 40000;int        Cow[1005];int tab[maxn];int n,d,k;void Table () {for (int s = 0; s < (1<<15); s++) {int cnt = 0;        int TMP = s;            while (TMP) {if (tmp&1) cnt++;        TMP = tmp>>1;    } Tab[s] = cnt;    }}void init () {int di;    memset (cow, 0, sizeof (cow));        for (int i = 0; i < n; i++) {scanf ("%d", &di);        int s = 0,tmp;            while (di--) {scanf ("%d", &tmp);        S |= (1<< (tmp-1));    } Cow[i] = s;    }}void solve () {int ans = 0;        for (int s = 0; s < (1<<d); s++) {if (Tab[s] > K) continue;        int cnt = 0;        for (int i = 0; i < n; i++) {if (s = = (S|cow[i])) cnt++;    } ans = max (ans, CNT); } printf ("%d\n", ans);}    int main () {table ();      while (scanf ("%d%d%d", &n,&d,&k)! = EOF) {  Init ();    Solve (); } return 0;}


POJ 2436 Usaco Silver

Related Article

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.