JZ junior OJ 1339. [2009 Nanhai junior] disease

Title Description

  Recently, there has been farm D (1 <= D <= 15) species of bacteria. John from his N (1 <= N <= 1,000) as much as possible cows more selected from milk. However, if the selected cows carrying more than K (1 <= K <= D) different kinds of bacteria, the production of milk on the failure. Please help John calculate the maximum number of cows can be selected.
 

Entry

First row: three integers N, D, K

The following N lines: The first line indicates the case of bacteria carried by a cow. Represents a first integer number of types of bacteria di carried by the cow, di behind each represents an integer numeral of these types of bacteria.

Export

Only a number M, optional maximum number of cows.
 

Sample input

 

Sample Output

 
 

Data range limit

 
 

prompt

Sample

 















Entry  

6 3 2         

0

1 1

1 2

1 3

2 2 1

2 2 1

select:

1,2,3,5,6

# 1 and # 2 only two bacteria

Export

5

    
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,ans,d,k,inf=-0x3f3f3f,flag[16],use[16]; 
 4 bool a[1001][16];
 5 void dfs(int x)
 6 {
 7     for(int i=use[x-1]+1;i<=d;i++)
 8     {
 9         if(flag[i]==0)
10         {
11             flag[i]=1;
12             use[x]=i;
13             if(x==k)
14             {
15                 for(int j=1;j<=n;j++)
16                 {
17                        for(int i=1;i<=d;i++)
18                     {
19                         if(a[j][i]==true&&flag[i]==0)
20                           {
21                         ans--;
22                         break;
23                         }
24                     }
25                 }
26                 if(ans>inf)
27                 inf=ans;
28                 ans=n;
29             }
30             else
31             dfs(x+1);    
32             flag[i]=0;
33             use[x]=0;
34         }
35     }
36 }
37 int main()
38 {
39     cin>>n>>d>>k;
40     ans=n;
41     for(int i=1;i<=n;i++)
42     {
43         scanf("%d",&a[0][0]);
44         for(int j=1;j<=a[0][0];j++)
45         {
46             scanf("%d",&a[0][1]);
47             a[i][a[0][1]]=true;
48         }
49     }
50     dfs(1);
51     cout<<inf;
52     return 0;
53 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11306734.html
Recommended