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. [java小笔记] 关于数组内存管理的理解

    数组是大多数编程语言都提供的一种复合结构,如果程序需要多个类型相同的变量时,就可以考虑定义一个数组,java语言的数组变量时引用类型的变量,因此具有java引用变量的特性.在使用数组之前必须对数组对象 ...

  2. 移动平台3G手机网站前端开发布局技巧

    本文转载至:移动平台3G手机网站前端开发布局技巧汇总 - 前端开发-武方博 您或许正在或准备参与一个WepApp项目,您或许正在Google搜索mobile development相 关的文章,您或许 ...

  3. Sql的实际应用

    sql实际应用-递归查询   1.既然要谈到sql,数据库表是必须的   2.数据结构     3.获取某个节点的所有子节点     传统的写法(sql2000) 很麻烦,暂且就不写了     来看看 ...

  4. Acitivity间数据的传递

    使用startActivityForResult方法进行数据传递.    MainActivity.java: public class MainActivity extends Activity { ...

  5. java星座、年龄、日期等

    星座: public static String getStar(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(dat ...

  6. C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型

    遇到一个想做的功能,但是实现不了,核心原因是因为对U3D的3D数学概念没有灵活吃透.故再次系统学习之—第三次学习3D数学. 本次,希望实现的功能很简单: 如在小地图中,希望可以动态画出Player当前 ...

  7. 第28条:利用有限制通配符来提升API的灵活性

    参数化类型是不可变的.对两个不同类型T1和T2而言,List<T1>与List<T2>没有父子类型关系. 考虑: public class Stack<E> { p ...

  8. iOS 简单理解类的本质

    1.类也是个对象 类是一个对象是Class类型的对象简称类对象 Class类型的定义 // 一个任意的类型,表示一个Objective-C类 typedef struct objc_class *Cl ...

  9. windows server 2008 集成raid卡驱动

    给服务器安装2008系统,一般都需要通过引导盘和操作系统盘来进行安装,安装过程比较繁琐时间也比较长,于是就想做一个集成了服务器驱动的2008系统盘,这样就可以直接用光盘安装,简单方便,第一步需要解决的 ...

  10. Make和Makefile

    无论是在Linux还是在Unix环境中,make都是一个非常重要的编译命令.不管是自己进行项目开发还是安装应用软件,我们都经常要用到make或make install.利用make工具,我们可以将大型 ...