2017年8月16日提高组T2 疾病
2017-08-18 15:27
351 查看
Description
现在有n个人,m种病,每个人都患有若干种病。若从这些人中选出若干个人来,但选出来的人的患病集合中不超过k种病,问最多能选出多少个人。Input
第一行三个整数n,m,k。接下来n行,每行第一个整数s,表示第i个人患了s种病,接下来s个整数,表示第i个人患的病。
Output
一行一个整数,表示答案。Sample Input
6 3 20
1 1
1 2
1 3
2 2 1
2 2 1
Sample Output
5Hint
【数据规模与约定】对于前30%的数据,1<=n<=10,1<=m<=10.
对于前100%的数据,1<=n<=1000,1<=m<=15,1<=k<=m.
Source
BY BPMSolution
这里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 | 1 int f[2][L], t ; 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; }
相关文章推荐
- SSL2703 2017年8月16日提高组T2 疾病(dfs)
- 【SSLGZ 2703】2017年8月16日提高组T2 疾病
- 2017年8月10号提高组T2 飞行
- 【SSLGZ 2677】2017年8月10号提高组T2 飞行
- C++&Pascal——NOIP2015提高组day1 t2——信息传递
- 2017年8月16日提高组T1 选数
- 2017.04.15【NOIP2017提高组】模拟赛B组 T2:渡河
- 2017年10月6日提高组T2 有趣的异或
- 【SSLGZ 2810】2017年10月30日提高组T2 数论
- 2017年11月3日提高组T2 生日宴会
- NOIP2010提高组T2:乌龟棋
- SSL2688 2017年8月14日提高组T2 温度
- 2017年8月15日提高组T2 购买
- 2017年9月16日提高组T2 B 三维导弹拦截
- [DP] ZROI 2017提高 5 T2. 石头剪刀布
- 2017年10月6日提高组T2 挖矿
- 2017年10月23日提高组T2 灵知的太阳信仰 单调队列优化dp
- 【SSLGZ 2790】2017年10月25日提高组T2 次方的运算
- SSL2795 2017年10月26日提高组T2 幸运值(组合)
- SSL2840 2017年11月7日提高组T2 轰炸(tarjan+拓扑)