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

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

【BZOJ】1688: [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

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

  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. 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )

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

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

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

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

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

随机推荐

  1. thinkphp session如何取数组

    thinkphp session如何取数组  session('user_auth.username'); 搞定!

  2. android 实现摇一摇功能

    实现“摇一摇”功能,其实很简单,就是检测手机的重力感应,具体实现代码如下: 一.在 AndroidManifest.xml 中添加操作权限 二.实现代码 package com.xs.test; im ...

  3. knockoutjs 静动态数据、行为绑定,计算属性及Sync同步更新 Value值更新事件控制

    data-bind="text: firstName"中data-bind属性是Knockout 用来显示关联UI和viewmodel的桥梁, text 表示把绑定的文本赋值给DO ...

  4. 【微软100题】定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。 如把字符串abcdef左旋转2位得到字符串cdefab。请实现字符串左旋转的函数。

    package test; /** * 定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部. 如把字符串abcdef左旋转2位得到字符串cdefab. 请实现字符串左旋转的函数. * ...

  5. 【RESTful风格】软件接口设计中RESTful风格

    REST = Representational State Transfer 表述性状态转移,是一种软甲接口设计风格.总之就是一种风格 REST基于:HTTP.HTML.JSON.XML.URI 这些 ...

  6. tomcat设置jvm参数

    http://www.quiee.com.cn/archives/592/ Tomcat默认可以使用的内存为128MB,Windows下,在文件{tomcat_home}/bin/catalina.b ...

  7. 初始化列表(const和引用成员)、拷贝构造函数

    一.构造函数初始化列表 推荐在构造函数初始化列表中进行初始化 构造函数的执行分为两个阶段 初始化段 普通计算段 (一).对象成员及其初始化  C++ Code  1 2 3 4 5 6 7 8 9 1 ...

  8. unity, inspector listview

    inspector中实现列表框: public override void OnInspectorGUI(){ bool isDoubleClick=false;        Event e = E ...

  9. 微软收购跨平台移动应用开发商Xamarin

    微软今天宣布收购移动应用跨平台开发商 Xamarin.收购金额未知.Xamarin 提供了通过 C# 开发 iOS.Android 和 Windows 原生移动应用的工具,以及云端应用測试平台 – 全 ...

  10. (Xilinx)FPGA中LVDS差分高速传输的实现

    https://wenku.baidu.com/view/24e8bad86f1aff00bed51ef8.html