zoukankan      html  css  js  c++  java
  • Disease Manangement 疾病管理

    posted on 2019-10-02 16:52:42

    Disease Manangement 疾病管理

    题面如下

    (N) 头牛,它们可能患有 (D) 种病,现在从这些牛中选出若干头来,但选出来的牛患病的集合中不过超过 (K) 种病。

    输入格式

    从标准输入读入数据。

    第一行输入三个正整数 (N(N leq 1000))(D(D leq 15))和$ K(K leq D)$。

    接下来 (N) 行,每行先输入一个整数 (a_i (a_i leq D)),然后输入 (D) 个正整数 (b_{ij} (b_{ij} leq D)),代表第 (i) 头牛患的 (a_i) 种病。

    输出格式

    输出到标准输出。

    输出一个整数,为最多能选出牛的数量。

    样例输入

    6 3 2
    0
    1 1
    1 2
    1 3
    2 2 1
    2 2 1
    

    样例输出

    5
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    int n, d, k, ds[1005], sum, ans;
    bool check(int s)
    {
    	int cnt = 0;
    	for(int i = s; i; i >>= 1) {
    		cnt += i & 1;
    	}
    	return cnt <= k;
    }
    int main()
    {
    	cin >> n >> d >> k;
    	for(int i = 1; i <= n; i++) {
    		int a, x;
    		cin >> a;
    		for(int j = 1; j <= a; j++) {
    			cin >> x;
    			ds[i] += (1 << (x - 1));
    		}
    	}
    	for(int i = 1 ;i < (1 << d); i++) {
    		if(check(i)) {
    			sum = 0;
    			for(int j = 1; j <= n; j++) {
    				if((ds[j] | i) == i) {
    					sum++;
    				}
    			}
    			ans = max(ans, sum);
    		}
    	}
    	cout << ans;
    return 0;
    }
    
    
  • 相关阅读:
    iOS,Layer
    iOS 手势冲突
    ECharts
    手动安装Package Control
    webstorm配置svn详解
    js 对象 类型转换
    google 跨域解决办法
    关于内层DIV设置margin-top不起作用的解决方案
    图片与文字在div里实现垂直水平都居中
    css3之3D翻牌效果
  • 原文地址:https://www.cnblogs.com/xuanfly/p/11808557.html
Copyright © 2011-2022 走看看