2017年8月16日提高组T2 疾病
来源:互联网 发布:王坚 阿里云 编辑:程序博客网 时间:2024/05/16 23:56
Description
现在有n个人,m种病,每个人都患有若干种病。若从这些人中选出若干个人来,但选出来的人的患病集合中不超过k种病,问最多能选出多少个人。
Input
第一行三个整数n,m,k。
接下来n行,每行第一个整数s,表示第i个人患了s种病,接下来s个整数,表示第i个人患的病。
Output
一行一个整数,表示答案。
Sample Input
6 3 2
0
1 1
1 2
1 3
2 2 1
2 2 1
Sample Output
5
Hint
【数据规模与约定】
对于前30%的数据,1<=n<=10,1<=m<=10.
对于前100%的数据,1<=n<=1000,1<=m<=15,1<=k<=m.
Source
BY BPM
Solution
这里m很小,dfs记忆化或者状压dp都可以
Code
#include <stdio.h>#include <string.h>#include <math.h>#include <queue>#include <vector>#include <algorithm>#define rep(i, st, ed) for (int i = st; i <= ed; i += 1)#define drp(i, st, ed) for (int i = st; i >= ed; i -= 1)#define erg(i, st) for (int i = ls[st]; i; i = e[i].next)#define fill(x, t) memset(x, t, sizeof(x))#define max(x, y) (x)>(y)?(x):(y)#define min(x, y) (x)<(y)?(x):(y)#define ll long long#define db double#define INF 0x3f3f3f3f#define N 1501#define L 1<<16 | 1int f[2][L], t[N];inline int read(){ int x=0,v=1; char ch=getchar(); while (ch<'0'||ch>'9'){if(ch=='-')v=-1; ch=getchar();} while (ch<='9'&&ch>='0'){x=x*10+ch-'0'; ch=getchar();} return x*v;}inline int count(int x){ int cnt = 0; while (x){ x -= x & (-x); cnt += 1; } return cnt;}int main(void){ int n = read(); int m = read(); int k = read(); rep(i, 1, n){ int c = read(); int s = 0; while (c --){s |= 1<<read()-1;} t[i] = s; } int lim = (1<<m)-1; rep(i, 0, n - 1){ rep(j, 0, lim){ f[(i + 1)&1][j] = max(f[i&1][j], f[(i + 1)&1][j]); f[(i + 1)&1][j|t[i+1]] = max(f[i&1][j] + 1, f[(i + 1)&1][j|t[i+1]]); } } int ans = 0; rep(i, 0, lim){ if (count(i) <= k){ ans = max(ans, f[n&1][i]); } } printf("%d\n", ans); return 0;}
阅读全文
1 0
- 2017年8月16日提高组T2 疾病
- 【SSLGZ 2703】2017年8月16日提高组T2 疾病
- SSL2703 2017年8月16日提高组T2 疾病(dfs)
- 2017年9月16日提高组T2 A
- 2017年8月9日提高组T2 覆盖
- 2017年8月9日提高组T2 覆盖
- 2017年8月9日提高组T2 覆盖
- 2017年8月15日提高组T2 购买
- 2017年8月14日提高组T2 温度
- 2017年8月15日提高组T2 购买
- 2017年8月17日提高组T2 考试
- 2017年10月6日提高组T2 挖矿
- 2017年10月6日提高组T2 挖矿
- 2017年11月1日提高组T2 树论
- 2017年8月8日提高组T2 呀!回文串
- SSL2671 2017年8月8日提高组T2 呀!回文串(dp)
- 2017年8月8日提高组T2 呀!回文串
- 【SSLGZ 2671】2017年8月8日提高组T2 呀!回文串
- 位图
- PopupWindow的简单使用
- LTC-PolygonLighting
- 关于I/O复用之select函数
- main(int argc, char ** argv)形参的理解与使用
- 2017年8月16日提高组T2 疾病
- FilterInputStream之装饰模式(例)
- Android编程权威指南(第2版)—第5章挑战练习
- 菜鸟初学JDK之ArrayList
- C语言实现哈希表查找算法
- POJ 2513 Colored Sticks(字典树+欧拉回路)
- http://www.gezila.com/tutorials/17290.html
- 未知:爱心蜗牛——题解
- Java的Swing应用中使用JavaFX的功能