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

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

题解:其实一开始想的很复杂,连树状数组都想过用上,但是后来发现貌似也就15种病,这样子就容易了——直接进行01状态压缩,然后枚举各种状态(HansBug:实际上,对于疾病的状态只需要保留刚刚好K种病即可,就算是更少的病种也可以剪掉,想想为什么^_^),然后就是各种位运算,然后A掉么么哒

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,x,ans:longint;
a:array[..] of longint;
function min(x,y:longint):longint;
begin
if x<y then min:=x else min:=y;
end;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
begin
readln(n,m,l);l:=min(l,m);ans:=;
for i:= to n do
begin
a[i]:=;
read(k);
for j:= to k do
begin
read(x);
a[i]:=a[i] or ( shl (x-));
end;
readln;
end;
for i:= to trunc(exp(ln()*m)-) do
begin
j:=i;k:=;
while j> do
begin
inc(k,j mod );
j:=j div ;
end;
if k<>l then continue;k:=;
for j:= to n do if (i or a[j])=i then inc(k);
ans:=max(ans,k);
end;
writeln(ans);
end.

1688: [Usaco2005 Open]Disease Manangement 疾病管理的更多相关文章

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

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

  2. 【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1688 很水的状压.. 提交了很多次优化的,但是还是100msT_T #include <cst ...

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

    Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the fa ...

  4. BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作

    #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #defin ...

  5. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  6. 【状压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)) ...

  7. bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理

    思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 ...

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

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

  9. 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理

    题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...

随机推荐

  1. Nginx之RTMP

    1. RTMP协议介绍 RTMP(Real Time Messaging Protocol)实时消息传送协议是Adobe Systems公司为Flash播放器和服务器之间音频.视频和数据传输开发的私有 ...

  2. Linux笔记(七) - 网络命令

    (1)给用户发信息:write例:write admin(ctrl+d结束)(2)发广播信息:wall例:wall hello world!(3)测试网络连通性:ping-c 发送次数例:ping - ...

  3. c# 应用NPOI 获取Excel中的图片,保存至本地的算法

    要求:读取excel中的图片,保存到指定路径 思路:  利用NPOI中 GetAllPictures()方法获取图片信息 步骤: 1.新建一个Windows窗体应用程序 2.桌面新建一个excel,贴 ...

  4. CSS的兼容性与BUG处理

    骨灰级清除浮动 .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility ...

  5. 关于ionic开发的一些总结(项目启动设置,app图标名称更改)

    1.更改包名称 一般项目刚生成时,ionic会根据项目名称自动给你生成一个包名.要修改包名的话,在根目录的config配置文件中,<widget id="x.x.x"换成自己 ...

  6. 构建自动化前端样式回归测试——BackstopJS篇

    在使用scss和less开发的时候,遇到过一件很有趣的事,因为网站需要支持响应式,就开了一个响应式样式框架,简单的几百行scss代码,居然生成了近100KB的css代码,因此决定重构这个样式库.而重构 ...

  7. React核心内容归纳总结

    状态.属性.组件API.组件的生命周期 当react的状态改变时,自动执行this.render()方法更新组件ES6写React的时候,事件里不会自动绑定this,需要自己绑定,或者直接在const ...

  8. express框架介绍

    //引入express模块 var express = require('express'); //调用express方法,接受其返回值(返回值为对象) var app = express(); ap ...

  9. WPScan初体验

    近日在朋友圈看某位dalao在Ubuntu上安装WPScan花了一个小时,于是洒家随手在Kali Linux上输入了wpscan,发现Kali里面已经装好了.于是决定玩两把WPScan. WordPr ...

  10. 毕向东tcp学习笔记1

    项目功能: 实现一次发送和接收,服务器接收客户端发送的内容并打印出来 用最通俗的语言讲解下,上图中大椭圆是服务器,A.C是客户端,当客户端和服务器通过socket建立连接后 1.两者之间形成一个通道, ...