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