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. 查看Buffer Pool使用情况--[转]

    ----源自:微软官方博客论坛 我的SQL Server buffer pool很大,有办法知道是哪些对象吃掉我的buffer Pool内存么?比方说,能否知道是哪个数据库,哪个表,哪个index占用 ...

  2. jQuery方法一览

    Attribute: $(”p”).addClass(css中定义的样式类型); 给某个元素添加样式 $(”img”).attr({src:”test.jpg”,alt:”test Image”}); ...

  3. 阿里云RDS实例内不同数据库之间的数据迁移

    适用场景 本文适用于使用DTS实现相同实例下库名不同的数据库之间的数据迁移.本文以使用DTS将同一RDS实例下的amptest库迁移到jiangliu_amptest库为例来说明如何使用DTS实现相同 ...

  4. SQL Server 错误(待补充)

    1.问题:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. 解决方法: 打开“ ...

  5. Introduction to SIFT (Scale-Invariant Feature Transform)

    SIFT OpenCV 官方文档: https://docs.opencv.org/master/da/df5/tutorial_py_sift_intro.html https://opencv-p ...

  6. php从memcache读取数据再批量写入mysql的方法

    这篇文章主要介绍了php从memcache读取数据再批量写入mysql的方法,可利用memcache缓解服务器读写压力,并实现数据库数据的写入操作,非常具有实用价值,需要的朋友可以参考下. 用 Mem ...

  7. Spring mvc注解方式使用事务回滚

    项目名:1ma1ma jdbc.xml <bean  id="dataSource" class="org.apache.commons.dbcp.BasicDat ...

  8. 微信client内部推荐项目总结

    如今实习的公司在面向企业提供招聘服务领域数一数二,而下半年的产品重点就在于移动端微信招聘项目.而这次内推项目开发属于微信招聘一个分支.     一.内推综述     乐帝之前读<招聘与录用> ...

  9. sql查看所有表大小的方法

    sql查看所有表大小的方法. 代码: declare @id int ) declare @pages int declare @dbname sysname ,) ,) ,) create tabl ...

  10. Node.js综述

    前言 本综述文章旨在帮助读者深入理解下Node.js的本质,不去关注应用的细节,我认为真正的技术问题只有在动手写代码的时候才会遇到,那个阶段解决问题才是真正有意义的.   发展史 Node.js是Ry ...