BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作
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.
题解:
树状数组中这是一个必备的工具,在状压 DP 中用这个也是十分方便的.
例如,要更新 $i$ 的二进制形式中 $1$ 的数量就可以用 $Num(i-lowbit(i))+1$ 来更新.
在本题中,我们先预处理出每一个患病数小于等于 $k$ 的所有子集.
每次读入的时候枚举一下,并更新到答案即可.
#include <bits/stdc++.h>
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 100000
using namespace std;
int F[1 << 16], s[1 << 16], v[1 << 16], f[1 << 16];
int n, D, k, tot = 0, ans = 0;
int main()
{
// setIO("input");
scanf("%d%d%d",&n,&D,&k);
for(int i = 1; i < (1 << D); ++i)
{
s[i] = s[i - (i & -i)] + 1;
if(s[i] <= k) v[++tot] = i;
}
for(int i = 1; i <= n; ++i)
{
int a, b;
scanf("%d",&a);
int t = 0;
for(int j = 1; j <= a; ++j)
{
scanf("%d",&b);
t += (1 << (b - 1));
}
for(int j = 1; j <= tot; ++j)
{
if((v[j] & t) == t)
++f[j], ans = max(ans, f[j]);
}
}
printf("%d\n",ans);
return 0;
}
BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作的更多相关文章
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理
Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the fa ...
- 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+背包dp
题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...
- 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}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...
- 【状压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)) ...
随机推荐
- springMvc--接受日期类型参数处理
这个问题,也即是springMvc如何进行参数类型的转换 , 以把client传过来一个String类型,转换为日期类型为例 步骤 1.controller /** * 接收日期类型参数 * 注意: ...
- request.getInputStream() 的两种解析方式
http://sagewsg.iteye.com/blog/1717923 byte[] bytes = new byte[1024 * 1024]; InputStream is; try { is ...
- Jmeter压测问题_Non HTTP response code: java.net.ConnectException
负载机压测,线程500,服务器根本无压力,负载机本身发的请求都是失败的 Sample result如下: Thread Name: 考勤(考勤提交) 1-255 Sample Start: 2018- ...
- Android studio 报错 gradel project sync failed Error:Cause: peer not authenticated
在网上找了半天,应该是找不到gradel的路径,试了网上非常多方法.本人解决例如以下: 在android studio中设置gradle.打开File-> settings->Gradle ...
- android測试工具MonkeyRunner--google官网翻译
近期在复习之前的笔记,在回想MonkeyRunner时看了看google官网的内容,写得不错.就翻译出来分享下.事实上google官网真是一个学习的好地方. 基础知识 MonkeyRunner工具提供 ...
- Android 输入管理服务-输入事件到达之后的处理流程
接上一篇博客"Android 输入管理服务启动过程的流程".这两天分析了Android 输入管理服务接收到输入事件之后的处理流程,详细流程例如以下面两图所看到的: 接下图
- 新手对ASP.NET MVC的疑惑
习惯了多年的WEB FORM开发方式,突然转向MVC,一下子懵了,晕头转向,好多不习惯,好多不明白,直到现在也没弄明白,只好先记下来,在应用中一一求解. 主要集中在视图(View)这里. 1.@Htm ...
- Delphi7中的函数与过程(Function and Procedure)
1.锁住空间的位置,可以选择Edit--->Lock component ,也可以在窗体设计面板下面找到组件排版功能栏,第二排里面有个带锁的图标,表示组件可以被锁住.点击一下,组件的大小和位置就 ...
- Androlid入门之文件系统操作(三)文件读写
import java.io.*; import android.app.Activity; import android.os.Bundle; import android.view.Vi ...
- django自带url模板标签的使用
django模板中url标签和view中的reverse(博客地址)功能相同,都是通过制定处理视图来返回一个url. 使用方法: {% url userEdit 12 %} 或者 {% url use ...