【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp
题目描述
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.
输入
* 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种病.
输出
* Line 1: M, the maximum number of cows which can be milked.
样例输入
6 3 2
0---------第一头牛患0种病
1 1------第二头牛患一种病,为第一种病.
1 2
1 3
2 2 1
2 2 1
样例输出
5
题解
状态压缩dp+背包dp
f[i]表示i状态时
不预处理num数组应该也行,尽管常数大些,反正都是一道水题
#include <cstdio>
#include <algorithm>
using namespace std;
int f[32770] , num[32770];
int main()
{
int n , d , k , i , j , x , y , ans = 0 , s;
scanf("%d%d%d" , &n , &d , &k);
for(i = 1 ; i < (1 << d) ; i ++ )
{
num[i] = num[i - (i & (-i))] + 1;
}
for(i = 1 ; i <= n ; i ++ )
{
s = 0;
scanf("%d" , &x);
while(x -- )
{
scanf("%d" , &y);
s |= 1 << (y - 1);
}
for(j = (1 << d) - 1 ; j >= 0 ; j -- )
{
if(num[j | s] <= k)
{
f[j | s] = max(f[j | s] , f[j] + 1);
ans = max(ans , f[j | s]);
}
}
}
printf("%d\n" , ans);
return 0;
}
【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp的更多相关文章
- 【状压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 ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 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 ...
- 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理
题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...
- [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688
分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理
Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the fa ...
- 【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1688 很水的状压.. 提交了很多次优化的,但是还是100msT_T #include <cst ...
随机推荐
- [Oracle]关于Oracle分页写法的性能分析及ROWNUM说明
关于分页写法的性能分析及ROWNUM的补充说明 分页写法 一.测试前数据准备 SQL> SELECT COUNT(*) FROM BPM_PROCVAR; COUNT(*) ---------- ...
- javascript之input字符串不为空
今天我们来讲如何判断这个java中字符串输入是否为空 ------------------------当只有一个input的时候,我们来进行个判断这个值是否为空-------------------- ...
- LeetCode: 62. Unique Paths(Medium)
1. 原题链接 https://leetcode.com/problems/unique-paths/description/ 2. 题目要求 给定一个m*n的棋盘,从左上角的格子开始移动,每次只能向 ...
- STM32堆栈指针疑问
1. 下面的代码看的不是很明白,百为stm32开发板光盘\测试程序\CortexM3\Mode_Privilege\project,堆是程序员分配和使用的,栈是编译器指定的,存放函数参数,临时变量. ...
- NB-IOT使用LWM2M移动onenet对接之MTU最大传输单元设置
1. 最近遇到的一个项目NB-IOT使用LWM2M移动onenet对接,要求设置传输的MTU,因此首先需要搞懂MTU是什么? 以太网的MTU值是1500 bytes,假设发送者的协议高层向IP层发送了 ...
- PostFix支持SMTP认证
安装cyrus-sasl yum -y install cyrus-sasl* 启动服务,开机启动 service saslauthd start chkconfig saslauthd on 配置p ...
- 内置方法(item系列)
class Foo: def __init__(self,name): self.name = name def __getitem__(self, item): # 获取时触发 print('get ...
- ConfigHelpers
--默认值可以不传 local ConfigHelpers = {} --设置物体高亮 target:设置对象 isLigth:是否高亮 seeThrough:是否穿透(默认为true,穿透) sta ...
- UniMelb Comp30022 IT Project (Capstone) - 2.Vuforia in Unity
2 Vuforia in Unity Tutorial: https://www.youtube.com/watch?v=X6djed8e4n0&t=213s Preparation: Dow ...
- leetcode-数数并说
数数并说 报数序列是指一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 " ...