【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 ...
随机推荐
- Java基础——NIO(二)非阻塞式网络通信与NIO2新增类库
一.NIO非阻塞式网络通信 1.阻塞与非阻塞的概念 传统的 IO 流都是阻塞式的.也就是说,当一个线程调用 read() 或 write() 时,该线程被阻塞,直到有一些数据被读取或写入,该线程在 ...
- 20145209刘一阳《JAVA程序设计》第1周学习总结
20145209刘一阳<JAVA程序设计>第1周学习总结 本周任务 了解Java基础知识 了解JVM.JRE与JDK,并下载.安装.测试JDK 了解PATH.CLASSPATH.SOURC ...
- day 11 绘制轮廓
#-*- coding:utf-8 -*- import cv2 import numpy as np #1.导入图像 #img = cv2.imread("home.jpg",0 ...
- VIO 初始化小结 - 10.17
最近几个月忙于博士毕业,找工作一直没有继续更新博客,希望以这一篇开始,每个月能够继续有几篇总结博客. 首先review一下比较著名的vio系统 Tightly coupled EKF: mainly ...
- java 类装饰
package TestIo; public class Test8 { public static void main(String[] args) { System.out.println(&qu ...
- unity share current game screen
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.IO; public class Tak ...
- 远离服务器宕机,腾讯WeTest正式推出服务器深度性能测试服务
WeTest 导读 随着城市发展趋向智慧化,不仅移动互联网应用正迅速融入出行.金融.医疗.娱乐等传统行业,跟随移动互联网成长起来的,还有用户对应用使用与消费的理性意识. 而在用户不断增加的同时,如何避 ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- uvaoj 213 - Message Decoding(二进制,输入技巧)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 180612-Spring之Yml配置文件加载问题
Yml配置文件加载问题 在resource目录下有一个application.yml文件,希望是通过@PropertySource注解,将配置文件数据读取到Environment中,然而调试发现数据始 ...