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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 727  Solved: 468
[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

OUTPUT DETAILS:

If FJ milks cows 1, 2, 3, 5, and 6, then the milk will have only two
diseases (#1 and #2), which is no greater than K (2).

HINT

Source

Silver

Analysis

不明不白的

和状态压缩DP打了场遭遇战

= =

你好,状压DP!

Code

 1 /**************************************************************
 2     Problem: 1688
 3     User: child
 4     Language: C++
 5     Result: Accepted
 6     Time:140 ms
 7     Memory:1456 kb
 8 ****************************************************************/
 9
10 #include<cstdio>
11 #include<iostream>
12 #define maxn 10100
13 using namespace std;
14
15 int n,d,k,num,tot,sick[maxn],DP[1<<15],ret;
16
17 bool check(int code){
18     int cnt = 0;
19     for(int i = 0;i < d;i++){
20         if((code>>i)&1) cnt++;
21     }return (cnt<=k)?1:0;
22 }
23
24 int main(){
25     scanf("%d%d%d",&n,&d,&k);
26
27     tot = (1<<d)-1;
28
29     for(int i = 1;i <= n;i++){
30         scanf("%d",&num);
31         int cnt;
32         for(int j = 1;j <= num;j++){
33             scanf("%d",&cnt);
34             sick[i] |= (1<<(cnt-1));
35         }
36     }
37
38     for(int i = 1;i <= n;i++)
39         for(int j = tot;j >= 0;j--)
40             DP[sick[i]|j] = max(DP[sick[i]|j],DP[j]+1);
41
42     for(int i = 0;i <= tot;i++) if(check(i)) ret = max(ret,DP[i]);
43
44     printf("%d",ret);
45
46     return 0;
47 }

= =

转载于:https://www.cnblogs.com/Chorolop/p/7569993.html

[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 Description ...

  2. bzoj 1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压)

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

  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 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

  7. [BZOJ] 1620: [Usaco2008 Nov]Time Management 时间管理

    1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 850  Solved ...

  8. BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

    最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...

  9. bzoj 3392: [Usaco2005 Feb]Part Acquisition 交易(最短路)

    3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 191  Solved ...

最新文章

  1. Windows 7环境下安装PHP 5.2.17
  2. 我崩溃了!月薪30K必须掌握的开源项目Java中SPI机制
  3. 推荐MIT的电路与电子学
  4. 爬虫css选择器,选择属性
  5. Hadoop安装与配置问题说明
  6. 我和学员那些事儿——涅槃重生的背后
  7. GCD -- 倒计时
  8. 计算机组成原理CRC相关运算,计算机组成原理复习
  9. XCTF-Web-高手区-shrine
  10. repr方法字符串输出实例对象的值
  11. Python二级笔记(9)
  12. 1.5 编程基础之循环控制 45 金币 方法二(python3实现)
  13. [DeeplearningAI笔记]改善深层神经网络_深度学习的实用层面1.10_1.12/梯度消失/梯度爆炸/权重初始化...
  14. Mycat的使用 - 03.全局序列号
  15. 新版万能声卡驱动-VoodooHDA-2.8.5
  16. wpsa3版面怎么变成a4、排版不变_wpsa4变a3排版打印
  17. PowerBI-筛选器函数-KEEPFILTERS
  18. 使用 PD Recover 恢复 PD 集群
  19. 上了学这么久,我才知道他们为什么可以这么爽
  20. 实现自己的音乐搜索软件(一)

热门文章

  1. Linux用某一用户创建文件,Linux创建用户,并赋予管理指定目录的权限
  2. impdp导入表结构和表数据_ORACLE数据库如何用datapump工具导出表结构然后导入到其它Schema下面...
  3. oracle odbc 设置_Oracle删除不干净怎么办?
  4. 金计算机一级,计算机一级B
  5. java date 转integer_java 中Date的各种格式转换
  6. Swift 设置字体
  7. 一维OTSU法、最小交叉熵法、二维OTSU法及C++源码
  8. html to txt研究
  9. 多媒体表示、描述、编码以及通信的相关规定和标准课程总结
  10. 单片机小白学步系列(二十一) IO口:基本的LED和按键操作