1688: [Usaco2005 Open]Disease Manangement 疾病管理
1688: [Usaco2005 Open]Disease Manangement 疾病管理
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 413 Solved: 275
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
题解:其实一开始想的很复杂,连树状数组都想过用上,但是后来发现貌似也就15种病,这样子就容易了——直接进行01状态压缩,然后枚举各种状态(HansBug:实际上,对于疾病的状态只需要保留刚刚好K种病即可,就算是更少的病种也可以剪掉,想想为什么^_^),然后就是各种位运算,然后A掉么么哒
1 /**************************************************************
2 Problem: 1688
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:80 ms
7 Memory:4132 kb
8 ****************************************************************/
9
10 var
11 i,j,k,l,m,n,x,ans:longint;
12 a:array[0..1000000] of longint;
13 function min(x,y:longint):longint;
14 begin
15 if x<y then min:=x else min:=y;
16 end;
17 function max(x,y:longint):longint;
18 begin
19 if x>y then max:=x else max:=y;
20 end;
21 begin
22 readln(n,m,l);l:=min(l,m);ans:=0;
23 for i:=1 to n do
24 begin
25 a[i]:=0;
26 read(k);
27 for j:=1 to k do
28 begin
29 read(x);
30 a[i]:=a[i] or (1 shl (x-1));
31 end;
32 readln;
33 end;
34 for i:=0 to trunc(exp(ln(2)*m)-1) do
35 begin
36 j:=i;k:=0;
37 while j>0 do
38 begin
39 inc(k,j mod 2);
40 j:=j div 2;
41 end;
42 if k<>l then continue;k:=0;
43 for j:=1 to n do if (i or a[j])=i then inc(k);
44 ans:=max(ans,k);
45 end;
46 writeln(ans);
47 end.
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Tsunami:一款功能强大的通用网络安全扫描工具
- Hive查看表/分区更新时间
- 直接通过手机抓取GPS的qxdm日志
- uniapp常用提示框uni.showToast(OBJECT)
- MySQL 索引(3)
- TS 设计模式04 - 适配器模式
- WebRTC | 原理、架构、框架目录、运行机制、核心类、PeerConnection调用过程等详解
- sql注入总结笔记
- WebRTC | Web服务器原理、Nodejs工作原理、Nodejs事件处理流程、V8引擎等要点解析
- OpenGL ES 3.0 | 围绕HelloTriangle实战案例 展开 渲染流程分析
- 基于 Kotlin + Netty 实现一个简单的 TCP 自定义协议
- dnslog带出——sqli-labs第8关
- Boolean源码解剖学
- SpringBoot+Mybatis整合出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found
- xss-labs第1~13关