BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理
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 疾病管理的更多相关文章
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作
#include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #defin ...
- 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )
我一开始写了个状压dp..然后没有滚动就MLE了... 其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间 ...
- 1688: [Usaco2005 Open]Disease Manangement 疾病管理
1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 413 So ...
- 【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1688 很水的状压.. 提交了很多次优化的,但是还是100msT_T #include <cst ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 【状压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)) ...
- bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理
思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 ...
- [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688
分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...
- 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理
题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...
随机推荐
- dedecms获取栏目下的频道列表
可以使用: {dede:channelartlist}标签 使用方法: {dede:channelartlist row='6'} <dl> <dt><a href= ...
- ORM中去除反射,添加Expression
之前接触了别人的ORM框架,感觉牛掰到不行,然后试着自己来写自己的ORM. 最初从园子里找到其他人写的反射的例子: List<PropertyInfo> pis = typeof(T).G ...
- c# xml 解析取值
//字符串 string result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>< ...
- C#面试基础问题
传入某个属性的set方法的隐含参数的名称是什么? value,它的类型和属性所声名的类型相同. 如何在C#中实现继承? 在类名后加上一个冒号,再加上基类的名称. C#支持多重继承么? 不支持.可以用接 ...
- C#中调用存储过程
[csharp] view plain copy print? string strsql = "Data Source=192.168.24.53;Initial Catalog=JF_C ...
- sqlserver中的聚合函数
聚合函数:就是按照一定的规则将多行(Row)数据汇总成一行的函数,对数据进行汇总前,还可以按特定的列(coloumn)将数据进行分组(group by)再汇总,然后按照再次给定的条件进行筛选 一:Co ...
- Android系统简介(上):历史渊源
上个月,看到微信的一系列文章,讲到Linux的鼻祖-李纳斯的传记<Just for Fun>, 其人神乎其能, 其人生过程非常有趣,值得每个程序员细细品味. 而实际上,对我而已,虽然做软件 ...
- C# 匿名类型
c#3.0引入匿名类型,其由编译器动态生成而非显式定义. using System;using System.Collections.Generic;using System.Linq;using S ...
- 最短路 dijkstra and floyd
二:最短路算法分析报告 背景 最短路问题(short-path problem):若网络中的每条边都有一个数值(长度.成本.时间等),则找出两节点(通常是源节点和阱节点)之间总权和最小的路径就是最短路 ...
- linux 判断指定用户对指定目录具有的权限
脚本名:power.sh 脚本内容: ------------------------------------------- 注意:必须以root 身份执行该脚本. 脚本power.sh 需要两个参数 ...