2019年10月2日夜4時52分42秒に掲載
疾病管理病Manangement
以下の質問表面
そこ\(N \)牛、彼らは苦痛かもしれ\(D \)これらの中の牛の頭の数から選ぶ今、病気の種類が、病気の牛のコレクションが、以上に選出された(K \)\種病気。
入力形式
データは標準入力から読み込まれます。
入力3つの正の整数の最初の行\(N(N \のLeq 1000)\)、\ (D(D \のLeq 15)\)と$ K(K \当量D) $。
次\(N \)列、整数を入力する各行(a_iを(a_iを\のLeq D)\)\、次いで型(\ D)を\正の整数を\(B_ {IJ}(B_ {IJ} \当量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;
}