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. linux版本的区分

    linux每个版本有好几种方式,刚学习的时候还不明白,了解了一下终于知道了 如下,以CentOS为例 1.CentOS系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.x-i386-bin- ...

  2. 关于Eclipse的常用快捷键

    最近用到了一些以前开发中没有用到的Eclipse中的快捷键,现在总结如下: Ctrl+Shift+G 全局 工作区中的引用 使用的图解: 在所选定的类上,按下Ctrl+Shift+G在Search的T ...

  3. 어느 도시 보유 하 면 사랑 이다(事態が発生すれば、ある都市の恋はしません)【Si les villes un amour】{If have love in a city}

    如果在北京拥有爱情 半夜在簋街喝啤酒 吃小龙虾 在后海的苦情歌声里 搂着你数那四合院的瓦片 如果在上海拥有爱情 去外滩手挽手 吹吹风 坐一下午 去城隍庙尝试各种小吃 嘲笑你嘴角残余的糯米糕 如果在杭州 ...

  4. c# 委托与异步调用

    背景:在winform UI中,有时需要对控件进行比较频繁的刷新,如进度条.picturebox显示视频等.如果在主线程进行这些刷新操作,操作还未完成就将执行下一次刷新,程序将发生错误:如果只是创建另 ...

  5. Totime iOS购物APP

    是为时光仓公司量身定做的一款移动app,根据本公司的要求,开发一款支持移动端购买的App.该项目主要包括六个大模块:商场特卖,特卖专场,时光商盟,个人中心,收藏,购物车. 1. 商场特卖——分为热卖商 ...

  6. JavaScript高级程序设计(第三版)学习笔记20、21、23章

    第20章,JSON JSON(JavaScript Object Notation,JavaScript对象表示法),是JavaScript的一个严格的子集. JSON可表示一下三种类型值: 简单值: ...

  7. nopCommerce添加支付插件

    之前完成了nopCommerce和汉化以及配置,今天继续对nopCommerce的研究,为了能够完成购物,我们就要将伟大的支付宝添加至其中了.支付宝插件下载 将Nop.Plugin.Payments. ...

  8. linux之let用法

    shell程序中的操作默认都是字符串操作,在要运行数学运算符的时候可能得到意想不到的答案: var=1 var=$var+1 echo $var output:1+1 从这个例子中可以看出shell字 ...

  9. pdf压缩之GSview

    今天实验室一个同学在网上投简历,网站要求投稿的简历pdf文件必须在100K以内.简历用的是ModernCV的模板,无论如何设置都在160k左右. 尝试用acrobat的压缩功能,也不能保证在100K以 ...

  10. Java _Map接口的使用(转载)

    转载自:http://blog.csdn.net/tomholmes7/article/details/2663379.转载请注明原作者地址 Map Map以按键/数值对的形式存储数据,和数组非常相似 ...