我一开始写了个状压dp..然后没有滚动就MLE了...

其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间复杂度....有点贪心的feel

------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define clr(x, c) memset(x, c, sizeof(x))
#define b(i) (1 << (i))
using namespace std;
const int maxn = 1005, maxd = 16;
int cow[maxn], lim, n, d;
bool jud(int s) {
int tot = 0;
rep(i, d) if(b(i) & s) tot++;
return tot <= lim;
}
int main() {
freopen("test.in", "r", stdin);
cin >> n >> d >> lim;
rep(i, n) {
cow[i] = 0;
int t, v;
scanf("%d", &t);
while(t--) {
scanf("%d", &v);
cow[i] |= b(v - 1);
}
}
int tot, ans = 0;
rep(s, b(d)) if(jud(s)) {
tot = 0;
rep(i, n) if((s | cow[i]) == s) tot++;
ans = max(tot, ans);
}
cout << ans << "\n";
return 0;
}

------------------------------------------------------------------------------

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

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

转载于:https://www.cnblogs.com/JSZX11556/p/4652537.html

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. bzoj 1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压)

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

  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. BZOJ1688|二进制枚举子集| 状态压缩DP

    Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) ...

  7. php 枚举类型比较,PHP 枚举类型的管理与设计知识点总结

    今天来分享下如何管理 PHP 的枚举类型. 一种常见的方式是,使用常量来代表枚举类型 const YES = '是'; const NO = '否'; 可以在这个基础上更进一步,将其封装成类,以便于管 ...

  8. [微信小程序毕业设计源码]基于小程序的健康管理(慢性疾病)系统

    目录 一.程序介绍: 三.文档目录: 四.运行截图: 五.数据库表: 六.代码展示: 七.更多学习目录: 八.互动留言 一.程序介绍: 文档:开发技术文档.参考LW.答辩PPT,部分项目另有其他文档 ...

  9. ef 在此上下文中只支持基本类型或枚举类型_Java枚举不应该成为你成功路上得绊脚石,源码给你讲解清楚

    现在在面试的过程中,基础得东西占的比重越来越高,尤其是对于Java底层得一些东西,比方说今天得内容---枚举,单纯说这些知识点其实并不难,甚至在日常得工作中用到的都不算多,但是,在面试的过程中会问到你 ...

最新文章

  1. 《Spring2之站立会议8》
  2. Altium Designer 规则设置Advance(Query)的使用
  3. 强大的原生DOM选择器querySelector和querySelectorAll
  4. Coursera课程Python for everyone:Quiz: Reading Web Data From Python
  5. boost::mpl::size相关的测试程序
  6. 16张扎心漫画,戳中女生私密日常,每一幕都很真实
  7. Spring MVC(三) 数据转换、格式化、校验
  8. pytorch 中 torch.optim.Adam 方法的使用和参数的解释
  9. bash脚本基础概念注意点
  10. php并发数据库操作,数据库的并发操作
  11. RFC8998+BabaSSL---让国密驶向更远的星辰大海
  12. 谷歌浏览器离线更换皮肤-安装谷歌浏览器插件与问题解决
  13. 01背包问题 —— 【算法设计】分支限界法
  14. 《人机交互技术》第二章 感知和认知基础
  15. 为大家介绍两款私藏宝藏可视化大屏制作软件
  16. VM虚拟机ssh免密登录其他主机
  17. CATIA CAA二次开发专题(八)---自定义特征模型
  18. APP系统开发模式一共有哪几种?
  19. Liunx本地Yum源配置
  20. 常用算法的计算复杂度

热门文章

  1. android+影子系统,神器再升级,手机影子系统来啦
  2. swagger内部类_spring boot 1.5.4 集成spring-Data-JPA(七)
  3. 小程序影藏溢出的gif_Win10即将推出GIF录制编辑工具,不再需要第三方软件了
  4. 系统学习机器学习之误差理论
  5. 汇编学习--7.9--寄存器
  6. c语言else不运行,if...else if..else第三句不执行?
  7. 嵌入式系统——流水线处理机执行时间计算
  8. 小白记事本--JAVA入门
  9. 监听input框值得改变
  10. Python 中缀表达式转换后缀表达式