BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理

题目

1688: [Usaco2005 Open]Disease Manangement 疾病管理

Time Limit: 5 Sec  Memory Limit: 64 MB

Description

Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Farmer John would like to milk as many 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. 有N头牛,它们可能患有D种病,现在从这些牛中选出若干头来,但选出来的牛患病的集合中不过超过K种病.

Output

* Line 1: M, the maximum number of cows which can be milked.

Sample Input

6 3 2
0---------第一头牛患0种病
1 1------第二头牛患一种病,为第一种病.
1 2
1 3
2 2 1
2 2 1

Sample Output

5

OUTPUT DETAILS:

If FJ milks cows 1, 2, 3, 5, and 6, then the milk will have only two
diseases (#1 and #2), which is no greater than K (2).

HINT

Source

Silver

题解

Orz我们用强大的Bitset暴力>_< 大力出奇迹!

代码

 1 /*Author:WNJXYK*/
 2 #include<cstdio>
 3 #include<bitset>
 4 using namespace std;
 5 const int Maxn=1000;
 6 int n,d,k;
 7 bitset<16> dis[Maxn+5];
 8 int Ans=0;
 9 int main(){
10     scanf("%d%d%d",&n,&d,&k);
11     for (int i=1;i<=n;i++){
12         int tmp;
13         scanf("%d",&tmp);
14         dis[i].reset();
15         for (int j=1;j<=tmp;j++){
16             int temp;
17             scanf("%d",&temp);
18             dis[i].set(temp-1);
19         }
20     }
21     for (int i=1;i<=(1<<d);i++){
22         int tmpAns=0;
23         bitset<16> tmp((long)i);
24         if (tmp.count()>k) continue;
25         for (int j=1;j<=n;j++) if ((tmp|dis[j])==tmp) tmpAns++;
26         Ans=(Ans<tmpAns?tmpAns:Ans);
27     }
28     printf("%d\n",Ans);
29     return 0;
30 }

时间: 2024-08-01 08:57:11

BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理的相关文章

1688: [Usaco2005 Open]Disease Manangement 疾病管理

1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 413  Solved: 275[Submit][Status][Discuss] Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Farmer John woul

bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理

思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 #define maxn 1900 int n,d,k; int a[maxn],f[maxs],num[maxs]; int main(){ scanf("%d%d%d",&n,&d,&k); for (int i=1;i<(1<<d);i++)

【状压dp】【bitset】bzoj1688 [Usaco2005 Open]Disease Manangement 疾病管理

vs(i)表示患i这种疾病的牛的集合. f(S)表示S集合的病被多少头牛患了. 枚举不在S中的疾病i,把除了i和S之外的所有病的牛集合记作St. f(S|i)=max{f(S)+((St|vs(i))^St)中牛的数量} #include<cstdio> #include<bitset> #include<algorithm> using namespace std; bitset<1000>vs[15],t,t2; int n,m,K,ans,f[1<

[BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】

题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MaxN = 200 + 5,

BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 shelter 点, 然后对于每个 farm x : S -> cow( x ) = cow( x ) 数量 , shelter( x ) -> T = shelter( x ) 容量 ; 对于每个dist( u , v ) <= m 的 cow( u ) -> shelter( v

BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; ++i ) #defin

[BZOJ] 1620: [Usaco2008 Nov]Time Management 时间管理

1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 850  Solved: 539[Submit][Status][Discuss] Description Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs

BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) differe