【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1688
很水的状压。。
提交了很多次优化的,但是还是100msT_T
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1005, M=70000;
int f[M], tot, n, d, k, b[17], c[N], ans; bool ck(int i) {
int s=0;
while(i) ++s, i-=i&-i;
return s<=k;
} int main() {
read(n); read(d); read(k);
for1(i, 1, 15) b[i]=1<<(i-1);
tot=(1<<d)-1;
for1(i, 1, n) {
int t=getint();
while(t--) c[i]+=b[getint()];
}
for1(l, 1, n) {
int t=c[l];
for3(i, tot, 0)
f[i|t]=max(f[i|t], f[i]+1);
}
for1(i, 0, tot) if(ck(i)) ans=max(ans, f[i]);
print(ans);
return 0;
}
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
0---------第一头牛患0种病
1 1------第二头牛患一种病,为第一种病.
1 2
1 3
2 2 1
2 2 1
Sample Output
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
【BZOJ】1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)的更多相关文章
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理 状压DP + 二进制 + 骚操作
#include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #defin ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理
Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the fa ...
- 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )
我一开始写了个状压dp..然后没有滚动就MLE了... 其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间 ...
- 1688: [Usaco2005 Open]Disease Manangement 疾病管理
1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 413 So ...
- 【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 ...
- bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理
思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 ...
- [Usaco2005 Open]Disease Manangement 疾病管理 BZOJ1688
分析: 这个题的状压DP还是比较裸的,考虑将疾病状压,得到DP方程:F[S]为疾病状态为S时的最多奶牛数量,F[S]=max{f[s]+1}; 记得预处理出每个状态下疾病数是多少... 附上代码: # ...
- 【状压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)) ...
随机推荐
- 转:不在同一个服务器上的数据库之间的数据操作(oracle/sql server的对比)
如何操做不在同一个数据库中的数据操作: 一.对于SQL server来讲: 1.采用创建链接服务器的方式: (1).创建链接服务器 exec sp_addlinkedserver ...
- 18-spring学习-AOP深入操作
范例:定义一个参数拦截 package com.Spring.aop; import org.springframework.stereotype.Component; @Component publ ...
- maven打包到本地仓库里面
mvn install:install-file -Dfile=D:/你的包名 -DgroupId=com.sdk4j -DartifactId=sdk4j -Dversion=1.0 -Dpack ...
- 类型转换运算符、*运算符重载、->运算符重载、operator new 和 operator delete
一.类型转换运算符 必须是成员函数,不能是友元函数 没有参数 不能指定返回类型 函数原型:operator 类型名(); C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 1 ...
- javascript sort方法容易犯错的地方
sort方法用来对数组排序非常方便.但是sort(func)这个func参数的构造却很容易混淆. sort判断func的返回值是判断正负,而不是ture和false.所以务必保证返回值要么负数要么正数 ...
- ICSharpCode.SharpZipLib工具压缩与解压缩zip文件
using System; using System.Collections.Generic; using System.IO; using System.Text; using ICSharpCod ...
- Refresh Tokens: When to Use Them and How They Interact with JWTs
In this post we will explore the concept of refresh tokens as defined by OAuth2. We will learn why t ...
- ubuntu下禁用和恢复触摸板
1.一般禁用选项在 settings > mouse and touchpad 中.(16.04通过实验)如果无法禁用或者希望恢复,向下看. 2.命令行键入: xinput ,插卡touchpa ...
- atitit.thumb生成高质量缩略图 php .net c++ java
atitit.java thumb生成高质量缩略图 php .net c++ 1. 图像缩放(image scaling)---平滑度(smoothness)和清晰度(sharpness) 1 2. ...
- 计算机图形学(一) 视频显示设备_1_CRT原理
第 1 章 图形系统概述 如今.计算机图形学的作用与应用已经得到了广泛承认.大量的图形硬件和软件系统已经应用 到了差点儿全部的领域.通用计算机甚至很多手持计算器也已经普遍具备 二维及三维 ...