【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理

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).

题解:状压DP,刷水有益健康。

#include <cstdio>
#include <iostream>
using namespace std;
int n,d,k,tot,ans;
int f[1<<15],s[1<<15],v[1<<15];
int main()
{
scanf("%d%d%d",&n,&d,&k);
int i,j,a,b,t;
for(i=1;i<1<<d;i++)
{
s[i]=s[i-(i&-i)]+1;
if(s[i]<=k) v[++tot]=i;
}
for(i=1;i<=n;i++)
{
scanf("%d",&a);
t=0;
for(j=1;j<=a;j++)
{
scanf("%d",&b);
t+=1<<b-1;
}
for(j=1;j<=tot;j++)
if((v[j]&t)==t)
f[j]++,ans=max(ans,f[j]);
}
printf("%d",ans);
return 0;
}

【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP的更多相关文章

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

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

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

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

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

  4. 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp

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

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

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

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

    1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 413  So ...

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

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

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

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

  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. yii2 session的使用方法

    yii2打开session use yii\web\Session; $session = Yii::$app->session; // check if a session is alread ...

  2. mysql中find_in_set()函数的使用

    首先举个例子来说: 有个文章表里面有个type字段,它存储的是文章类型,有 1头条.2推荐.3热点.4图文等等 .现在有篇文章他既是头条,又是热点,还是图文,type中以 1,3,4 的格式存储.那我 ...

  3. php5 数据类型

    一.PHP主要有一下几种数据类型 String(字符串), Integer(整型), Float(浮点型), Boolean(布尔型), Array(数组), Object(对象), NULL(空值) ...

  4. openjdk 完全编译指南

    从openjdk.java.net下载openjdk的软件包,你就获得了所有相关的源码. 强烈建议首先仔细看懂 README-builds.html 指南. 在执行 make all 之前,首先要 执 ...

  5. 删除Tomcat服务及其它注意

    使用sc delete Tomcat7(注意服务名是Tomcat7 不是Apache......Tomcat7.0). 绿色版无法启动的话,需要先ervice.bat install注册一下服务. 如 ...

  6. shell--3.运算符

    1.注意 原生bash不支持简单的数学运算,但是可以用其它命令来实现如 awk 和expr ,expr最常用 val=`expr 2 + 3` echo "结果 ${val}" # ...

  7. 【Android开发实践】android.view.InflateException: Binary XML file line #12: Error inflating class fragment问题解决

    一般出现的原因是fragment引入的包错了,应该是import android.app.ListFragment;而不是import android.support.v4.app.ListFragm ...

  8. HK&&CC JS学习:第一周——NO.2this

    1)常用的命名规范:     aXXXX:aBtn 说明获取的是一组元素:--类数组     oXXX:oBtn 说明获取的是一个元素->对象         对象有两个重要的特点:属性 和 方 ...

  9. IE 8 下的 box-sizing 和 min-* 属性

    在非 IE 浏览器中,默认情况下 width 属性指的是内容区域(content)的宽度. IE 6+ 中,如果浏览器以标准模型渲染,和非 IE 浏览器的表现是一致的:如果浏览器以怪癖模式渲染,则 w ...

  10. SVN版本控制与分支设置

    使用SVN+Eclipse做软件版本控制. (2009年5月) 1,SVN目录结构 Trunk : 主干目录,此目录下的文件为基准文件 Branches : 用于开发的分支目录 Tags : 用于发布 ...