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 1

6 3 2
0———第一头牛患0种病
1 1——第二头牛患一种病,为第一种病.
1 2
1 3
2 2 1
2 2 1

Sample Output 1

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

Source

[BZOJ1688][Usaco2005 Open]

只是稍微接触过一点状压dp,没有一点思路。

首先预处理出 num[i] 表示状态i有几种病,用a[i]存每头牛的状态。

然后dp[i] 表示状态为i的最多牛数

那么转移方程为 dp[s] = max(dp[s] , dp[S] + 1); 其中s=a[i] | S;

 #include<bits/stdc++.h>
using namespace std;
const int maxn=; const int M=<<;
int a[maxn],num[M],dp[M];
int main() {
for(int i=;i<M;i++) num[i]=num[i>>]+(i&);
int n,m,k;
while(~scanf("%d%d%d",&n,&m,&k)) {
memset(a,,sizeof(a));
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++) {
int x;
scanf("%d",&x);
while(x--) {
int val;
scanf("%d",&val);
a[i]|=<<(val-);//将第val位变为1
}
}
for(int i=;i<=n;i++) {
for(int S=(<<m)-;S>=;S--) {//枚举状态
int s=a[i]|S;//由S可以到达的状态s
if(num[s]>k) continue;
dp[s]=max(dp[s],dp[S]+);//那么s壮态数量 就可能更新
}
}
int ans=-;
for(int i=;i<M;i++) {
if(num[i]>k) continue;
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
}

#include<bits/stdc++.h>using namespace std;const int maxn=1010;
const int M=1<<15;int a[maxn],num[M],dp[M];int main() {    for(int i=0;i<M;i++) num[i]=num[i>>1]+(i&1);    int n,m,k;    while(~scanf("%d%d%d",&n,&m,&k)) {        memset(a,0,sizeof(a));        memset(dp,0,sizeof(dp));        for(int i=1;i<=n;i++) {            int x;            scanf("%d",&x);            while(x--) {                int val;                scanf("%d",&val);                a[i]|=1<<(val-1);//将第val位变为1            }        }        for(int i=1;i<=n;i++) {            for(int S=(1<<m)-1;S>=0;S--) {//枚举状态                int s=a[i]|S;//由S可以到达的状态s                if(num[s]>k) continue;                dp[s]=max(dp[s],dp[S]+1);//那么s壮态数量 就可能更新            }        }        int ans=-1;        for(int i=0;i<M;i++) {            if(num[i]>k) continue;            ans=max(ans,dp[i]);        }        printf("%d\n",ans);    }}

BZOJ1688 Disease Manangement 疾病管理的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 无法访问windows安装服务。发生这种情况的可能是您在安全模式下运行windows,或是没有正确安装windows安装,。请与技术支持人员联系以获得帮助。

    解决办法: 1.命令提示符下输入:msiexec/regserver 2.在“管理工具”→“服务”中启动windows Installer 程序员的基础教程:菜鸟程序员

  2. Anaconda 安装和配置

    Anaconda 安装和配置 1. Anaconda 安装 Anaconda说明及安装过程:Anaconda详细安装使用教程 2. Anaconda和Pip源修改 Anaconda源修改:打开Anac ...

  3. 案例研究:手机APP的UI设计流程

    以下内容由Mockplus(http://www.mockplus.cn)团队翻译整理,仅供学习交流. UI设计——不仅仅是创造漂亮的图像. 面临的挑战 我为自己提供了一个绝佳的机会来训练我的视觉设计 ...

  4. windows 安装 mysql5.7.17

    下载mysql 进入官网:https://www.mysql.com/ 单击[Downloads]选项卡 最下面有个[  MySQL Community Edition (GPL)],单击[Commu ...

  5. YII2 自动 created_at created_by updated_by updated_at

    use yii\behaviors\TimestampBehavior; use yii\behaviors\BlameableBehavior; use yii\db\Expression; /** ...

  6. left join、right join、inner join、full join

    转自:某一网友 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join ...

  7. SSH 密钥登录 SecureCRT

    https://www.qcloud.com/doc/product/213/2036 1.3. 使用SecureCRT登录 1.3.1. 复制公钥 登录腾讯云控制台,点击[云服务器]-[SSH密钥] ...

  8. numpy.convolve()

    卷积函数: numpy.convolve(a, v, mode='full') Parameters: a : (N,) array_like First one-dimensional input ...

  9. [改善] dcef3 for Firemonkey 浏览器控件,拉动窗体大小会闪烁的问题

    问题:dcef3 for Firemonkey 浏览器控件,拉动窗体大小会闪烁的问题 修改源码:ceffmx.pas 找到 procedure TCustomChromiumFMX.Resize; 修 ...

  10. [LeetCode 题解]: UniquePaths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...