2017年8月16日提高组T2 疾病

21 篇文章 0 订阅

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 | 1
int 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值