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.

题解:

`2^d`枚举选那些病,统计答案。

代码:

#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: [Usaco2005 Open]Disease Manangement 疾病管理的更多相关文章

  1. BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作

    #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #defin ...

  2. 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )

    我一开始写了个状压dp..然后没有滚动就MLE了... 其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间 ...

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

    1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 413  So ...

  4. 【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1688 很水的状压.. 提交了很多次优化的,但是还是100msT_T #include <cst ...

  5. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  6. 【状压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)) ...

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

    思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 ...

  8. [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688

    分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...

  9. 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理

    题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...

随机推荐

  1. Servlet线程安全问题

    Servlet采用单实例多线程方式运行,因此是线程不安全的.默认情况下,非分布式系统,Servlet容器只会维护一个Servlet的实例,当多个请求到达同一个Servlet时,Servlet容器会启动 ...

  2. 安卓开发错误:The type android.support.v4.app.TaskStackBuilder$SupportParentable cannot be resolved.

    今天在使用低版本下的ActionBar,在继承ActionBarActivity时报了"The type Android.support.v4.app.TaskStackBuilder$Su ...

  3. ExtJs store加载

    当store加载数据对象中,如果带有success:false,store会认为加载数据失败,不予将得到的数据显示在界面上,所有记得在返回数据对象的同时返回success:true;

  4. 如果利用storyboard创建cell中标识符identifier的正确设置

    今天打算用storyboard直接生成cell,但是总是提示数据源没设置,一直报错. 我就奇了怪了,明明标识符设置了,但是还是不行,仔细分析之后才发想,原来是因为标识符位置填错了.请看下面截图中正确的 ...

  5. iOS推送通知流程

    ①注册推送通知使用方法:registerUserNotificationSettings, registerForRemoteNotifications ④APP发送deviceToken到第三方: ...

  6. android Locat工作日志的使用

    #3.Logcat日志工具的使用 日志的等级: error:最高等级,错误信息,红色 warn:比较高,警告信息,橙色 debug:较高,调试信息,蓝色 info:一般,一般信息,绿色 verbose ...

  7. [leetcode] 399. Evaluate Division

    我是链接 看到这道题,2个点和一个权值,然后想到图,但是leetcode就是这样,没给数据范围,感觉写起来很费劲,然后就开始用图来做,添加边的时候,注意正向边和反向变,然后查询的时候,先判断2个点是否 ...

  8. c&c++函数的参数和返回值的传递终结版

    c++函数的参数和返回值的传递方式有三种:值传递.指针传递和引用传递. 在这之前先看几个例子: 一, int a=10; int b=a; b+=10; 此时b是a的一个拷贝,改变b的值,a并不会受到 ...

  9. 霍纳法则(Horner's rule)

    卡在hdu 1402 的高精度乘法了,要用FFT(快速傅里叶变换),然后看到了这个霍纳法则,顺便就写下来了. 霍纳法则:求多项式值的一个快速算法. 简单介绍: 假设有n+2个数 , a0,a1,a2, ...

  10. top每个参数的意义

    上图来源于本人虚拟机,作为每个参数解释的参考 10:32:20:现在的时间 up 1 min : 服务器运行的时长 1 user:现在只有1个用户登录 load average: 0.74, 0.25 ...