细菌(disease)解题报告 - 搜索与回朔

细菌(2009jxd)

Time Limit:1000MS  Memory Limit:65536K
Total Submit:3 Accepted:1

Description

近期,农场出现了D (1<= D <=15)种细菌。John 要从他的 N (1<= N <=1,000)头奶牛中尽可能多地选些产奶。但是如果选中的奶牛携带了超过 K (1<= K <=D)种不同细菌,所生产的奶就不合格。请你帮助John 计算出最多可以选择多少头奶牛。

Input

第一行:三个整数 N, D, K
下面N行:第i行表示一头牛所携带的细菌情况。第一个整数 di 表示这头牛所携带的细菌种类数,后面di个整数表示这些细菌的各自种类标号。


Output

只一个数 M,最大可选奶牛数。

Sample Input


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


Sample Output


5

选择:
1,2,3,5,6
只有1#和2#两种细菌


反思:

这题应该是最简单了的,简单一个搜索就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,d,k,ans=0,ni,tmp;
bool bo[100000];
int cow[1001];

int check(int i)
{
int t=0;
while(i>0)
{
int p=i&-i;
t++;
i-=p;
}
return t;
}

int main()
{
freopen("disease.in","r",stdin);
freopen("disease.out","w",stdout);

memset(bo,true,sizeof(bo));
memset(cow,0,sizeof(cow));
scanf("%d%d%d",&n,&d,&k);

for(int i=1;i<=n;++i)
{
scanf("%d",&ni);
for(int j=0;j<ni;++j)
{
scanf("%d",&tmp);
cow[i]+=(1<<(tmp-1));
}
}

for(int i=1;i<=(1<<d);++i)
{
if(check(i)>k)
bo[i]=false;
}

for(int i=1;i<=(1<<d);++i)
{
int jl=0;
if(bo[i])
for(int j=1;j<=n;++j)
{
int tt=(cow[j]&i);
if(tt==cow[j])
++jl;
}
if(jl>ans)
ans=jl;
}

/* for(int i=1;i<=(1<<d);++i)
if(bo[i])
cout<<i<<endl;*/

printf("%d",ans);
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值