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

 
无脑状压
水~
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=1000+10,maxd=17,maxs=(1<<15)+10;
int n,d,k,mi[maxd],ds[maxn],nowans,ans; int aa;char cc;
int read() {
aa=0;cc=getchar();
while(cc<'0'||cc>'9') cc=getchar();
while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
return aa;
} bool ok(int x) {
int tot=0;
while(x) {
x-=(x&(-x));
tot++;
}
return tot<=k;
} int main() {
n=read();d=read();k=read();
mi[1]=1;int x,y;
for(int i=2;i<=d;++i) mi[i]=mi[i-1]<<1;
for(int i=1;i<=n;++i) {
x=read();
for(int j=1;j<=x;++j) {
y=read();
ds[i]+=mi[y];
}
}
for(int x=0;x<(1<<d);++x) if(ok(x)){
nowans=0;
for(int j=1;j<=n;++j) {
y=(x|ds[j]);
if(y==x) nowans++;
}
ans=max(ans,nowans);
}
printf("%d",ans);
return 0;
}

  

bzoj1688 疾病管理的更多相关文章

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

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

  2. BZOJ1688 Disease Manangement 疾病管理

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

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

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

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

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

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

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

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

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

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

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

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

  9. 【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 ...

随机推荐

  1. windows2008解决必须使用角色管理工具安装或配置 NET3.5 sp1问题

    win2008系统安装网站环境系统的时候常常提示:必须使用角色管理工具 安装或配置microsoft.net framework 3.5 sp1 ,导致安装不成功. 原因在于windows2008系统 ...

  2. combobox 的onLoadSuccess执行两次解决办法和 取值赋值

    加红色字部分 jsp <input class="easyui-combobox" id="keshi" name="keshi" v ...

  3. int 13h,磁盘中断

    直接磁盘服务(Direct Disk Service——INT 13H)  00H —磁盘系统复位 01H —读取磁盘系统状态 02H —读扇区 03H —写扇区 04H —检验扇区 05H —格式化 ...

  4. ElasticSearch基本操作(安装,索引的创建和删除,映射)

    ElasticSearch基于Lucene的搜索服务器,支持分布式,提供REST接口,可用于云计算,可以实现实时搜索,开源免费.这时很官方的一句话,在使用之前,我们简单的介绍一下安装过程.在官网下载之 ...

  5. 手写Function.bind函数

    if(!Function.prototype.bind){ Function.prototype.bind = function(oThis){ if(typeof this !=="fun ...

  6. reduce个数问题

    reduce的数目到底和哪些因素有关 1.我们知道map的数量和文件数.文件大小.块大小.以及split大小有关,而reduce的数量跟哪些因素有关呢?  设置mapred.tasktracker.r ...

  7. 2019-8-31-C#-程序集数量对软件启动性能的影响

    title author date CreateTime categories C# 程序集数量对软件启动性能的影响 lindexi 2019-08-31 16:55:58 +0800 2018-10 ...

  8. TZOJ 2965 A Coin Game(DP)

    描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game cal ...

  9. leetcode 352 & leetcode 239 & leetcode 295 & leetcode 53 & leetcode 209

    lc352 Data Stream as Disjoint Intervals 可以用treemap解 key保存interval的start,value保存interval的end.分别找出当前va ...

  10. wpf绑定元素属性