1688: [Usaco2005 Open]Disease Manangement 疾病管理

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 706  Solved: 456
[Submit][Status][Discuss]

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.

Sample Input

6 3 2
0---------第一头牛患0种病
1 1------第二头牛患一种病,为第一种病
1 2
1 3
2 2 1
2 2 1

Sample Output

5

题目中文部分少了一句话:答案要尽可能大

因为疾病不超过15种,所以可以暴力每一种疾病组合方式,然后判断只患这些疾病的有多少头牛

复杂度O(2^d+C(d, k)*nd)

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct
{int m;int a[17];
}Cow;
Cow s[1005];
int main(void)
{int n, i, j, d, k, p, sum, ans, b[17];scanf("%d%d%d", &n, &d, &k);for(i=1;i<=n;i++){scanf("%d", &s[i].m);for(j=1;j<=s[i].m;j++)scanf("%d", &s[i].a[j]);}ans = 0;for(i=1;i<(1<<d);i++){sum = 0;memset(b, 0, sizeof(b));for(j=0;j<=d-1;j++){if(i&(1<<j))b[j+1] = 1, sum++;}if(sum!=k)continue;sum = 0;for(j=1;j<=n;j++){for(p=1;p<=s[j].m;p++){if(b[s[j].a[p]]==0)break;}if(p==s[j].m+1)sum++;}ans = max(ans, sum);}printf("%d\n", ans);return 0;
}
/*
6 3 2
0
1 1
1 2
1 3
2 2 1
2 2 1
*/

bzoj 1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压)相关推荐

  1. [BZOJ] 1688: [Usaco2005 Open]Disease Manangement 疾病管理

    1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 727  S ...

  2. BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理

    题目 1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MB Description ...

  3. 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )

    我一开始写了个状压dp..然后没有滚动就MLE了... 其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间 ...

  4. bzoj1688[Usaco2005 Open]Disease Manangement 疾病管理*

    bzoj1688[Usaco2005 Open]Disease Manangement 疾病管理 题意: n头牛,d种疾病,每头牛都患一些疾病,现在要求选出最多的牛,使这些牛患病的种类数不超过k.n≤ ...

  5. [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688

    分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...

  6. [BZOJ 1879][SDOI 2009]Bill的挑战 题解(状压DP)

    [BZOJ 1879][SDOI 2009]Bill的挑战 Description Solution 1.考虑状压的方式. 方案1:如果我们把每一个字符串压起来,用一个布尔数组表示与每一个字母的匹配关 ...

  7. 【BZOJ 4565】 [Haoi2016]字符合并 区间dp+状压

    考试的时候由于总是搞这道题导致爆零~~~~~(神™倒序难度.....) 考试的时候想着想着想用状压,但是觉得不行又想用区间dp,然而正解是状压着搞区间,这充分说明了一件事,状压不是只是一种dp而是一种 ...

  8. 【BZOJ】1076 [SCOI2008]奖励关 期望DP+状压DP

    [题意]n种宝物,k关游戏,每关游戏给出一种宝物,可捡可不捡.每种宝物有一个价值(有负数).每个宝物有前提宝物列表,必须在前面的关卡取得列表宝物才能捡起这个宝物,求期望收益.k<=100,n&l ...

  9. 【BZOJ 2595】2595: [Wc2008]游览计划 (状压DP+spfa,斯坦纳树?)

    2595: [Wc2008]游览计划 Time Limit: 10 Sec  Memory Limit: 256 MBSec  Special Judge Submit: 1572  Solved:  ...

最新文章

  1. linux源码安装浏览器,Linux系统手动安装Firefox浏览器
  2. 我的WCF之旅(6):在Winform Application中调用Duplex Service出现TimeoutException的原因和解决方案...
  3. LA 4254 Processor 处理器 【二分 贪心 优先队列】
  4. 拼多多“京东化”:自建物流重农卖菜是赚谁的钱?
  5. 120. 三角形最小路径和
  6. 文件系统_Docker文件系统实战
  7. 载:看了你能懂几个?
  8. cmd中如何查看当前绝对路径_如何查看 Linux 中文件打开情况?
  9. Java Bullshifier –生成大量随机代码库
  10. 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight
  11. bootstrap table格式化字符串_你要的PHP字符串处理函数都在这了!
  12. html中链接不自动变色,HTML 点击 标签 链接 点击之后变色-转发【已解决】
  13. 高性能Web框架FastAPI v0.62.0
  14. input 提交表单按钮 背景图片的完美设置 (隐藏字体)
  15. 前端把信息放在弹框里显示出来_jsp + js + 前端弹出框
  16. 如何将servlet中的变量在jsp页面中显示---jsp中的jstl表达式(C标签)
  17. winform 报表的基本使用
  18. CS224N笔记——反向传播
  19. MacBook 电脑Touch Bar该怎么设置
  20. JAVA面试题解惑系列(十)——话说多线程

热门文章

  1. python软件-Python软件下载|Python最新版本v3.5.1 下载_当游网
  2. 自学python需要安装什么-终于明白python需要学什么
  3. python是什么软件-python是什么软件
  4. python用什么编译器-Python必学之编译器用哪个好?你用错了吧!
  5. 零基础学python知乎-零基础人员可以学习python吗?|Python培训基础教程
  6. python自学看什么书-自学Python一年,看了几十本书,我发现了这些捷径!
  7. lync显示无法找到服务器,Lync 2013 已知问题
  8. bigdecimal java 最大值_Java中的数学运算BigDecimal
  9. npm工具运行Vue项目
  10. DB2查询主键、索引、表约束