Loading

题解 Disease Manangement 疾病管理

题解

本题是一个比较有变化的状压 \(DP\),方程很好想,不多赘述,留坑

#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define pe(x) (1<<(x))
#define p(i) ++i
#define ri register int
using namespace std;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
int s[1010],num[pe(15)],di;
int main() {
	int n=read(),d=read(),k=read();
	for (ri i(1);i<=n;p(i)) {
		int st=read();
		for (ri j(1);j<=st;p(j)) di=read(),s[i]|=pe(di-1);
	}
	num[0]=0;
	int ans=0;
	for (ri i(0);i<pe(d);p(i)) {
		if (i) num[i]=num[i^lowbit(i)]+1;
		if (num[i]>k) continue;
		int sum=0;
		for (ri j(1);j<=n;p(j)) {
			if ((s[j]&i)==s[j]) sum++;
		}
		ans=max(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}
posted @ 2021-01-27 10:29  ナンカエデ  阅读(78)  评论(0编辑  收藏  举报