SSL2703 2017年8月16日提高组T2 疾病(dfs)
2017-08-17 10:57
609 查看
2017年8月16日提高组T2 疾病
Description现在有n个人,m种病,每个人都患有若干种病。若从这些人中选出若干个人来,但选出来的人的患病集合中不超过k种病,问最多能选出多少个人。
Input
第一行三个整数n,m,k。
接下来n行,每行第一个整数s,表示第i个人患了s种病,接下来s个整数,表示第i个人患的病。
Output
一行一个整数,表示答案。
【数据规模与约定】
对于前30%的数据,1<=n<=10,1<=m<=10.
对于前100%的数据,1<=n<=1000,1<=m<=15,1<=k<=m.
分析:观察数据可以发现m很小,所以按m搜索就行啦。
代码
#include <cstdio> #define maxn 1005 using namespace std; int a[maxn][20],n,m,k,ans; bool f[20]; int find() { int s=0; for (int i=1;i<=n;i++) { bool fl=false; for (int j=1;j<=a[i][0];j++) if (!f[a[i][j]]) { fl=true; break; } if (!fl) s++; } return s; } void dfs(int dep,int tot) { if (tot==k) { int x=find(); if (x>ans) ans=x; return; } if (dep>m) return; f[dep]=true; dfs(dep+1,tot+1); f[dep]=false; dfs(dep+1,tot); } int main() { // freopen("disease.in","r",stdin); //freopen("disease.out","w",stdout); scanf("%d%d%d",&n,&m,&k); for (int i=1;i<=n;i++) { scanf("%d",&a[i][0]); for (int j=1;j<=a[i][0];j++) scanf("%d",&a[i][j]); } if (m==k) ans=n; else dfs(1,0); printf("%d",ans); }
相关文章推荐
- 【SSLGZ 2703】2017年8月16日提高组T2 疾病
- 2017年8月16日提高组T2 疾病
- SSL2675 2017年8月9日提高组T3 难题(dfs)
- 挖地雷_1996年分区联赛提高组之三_ssl1071_dfs
- SSL2834 2017年11月4日提高组T2 背包(二分)
- SSL2835 2017年11月4日提高组T2 字典序(堆+拓扑序)
- SSL2795 2017年10月26日提高组T2 幸运值(组合)
- SSL2845 2017年11月8日提高组T2 序列操作(贪心,树状数组,差分)
- SSL2668 2017年8月7日提高组T1 根(dfs)
- SSL2688 2017年8月14日提高组T2 温度
- SSL2810 2017年10月30日提高组T2 数论(math)
- SSL2843 2017年11月8日提高组T2 拆网线(树形dp)
- SSL2812 2017年10月30日提高组T2 凤凰院凶真(dp,LCIS)
- SSL2844 2017年11月8日提高组T2 奇怪的队列(线段树贪心)
- 【DFS】【最短路】【spfa】【BFS】洛谷P2296 NOIP2014提高组 day2 T2 寻找道路
- SSL2706 2017年8月17日提高组T2 考试(贪心)
- SSL2677 2017年8月10号提高组T2 飞行(spfa)
- SSL2759 2017年10月6日提高组T2 挖矿(dp)
- SSL2731 2017年9月16日提高组T2 学校联网(kruskal)
- SSL2674 2017年8月9日提高组T2 覆盖(dp)