-
Notifications
You must be signed in to change notification settings - Fork 0
/
11825.cpp
49 lines (46 loc) · 941 Bytes
/
11825.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<sstream>
#include<utility>
#include<deque>
#include<list>
#include<set>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<ctime>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++)
const int maxn = 1<<16+5;
int n,kase;
int cover[maxn];
int p[20];
int f[maxn];
int main(){
while(cin>>n&&n){
memset(p,0,sizeof p);
rep(i,0,n){
p[i] += 1<<i;
int m; cin>>m;
rep(j,0,m) {int a; cin>>a; p[i] += 1<<a;}
}
rep(i,0,1<<n){
cover[i] = 0;
rep(j,0,n) if(i & (1<<j)) cover[i] |= p[j];
}
f[0] = 0;
int all = (1<<n)-1;
for(int s = 1; s< 1<<n; s++){
f[s] = 0;
for(int s0 = s; s0; s0 = (s0 - 1)&s ){
if(cover[s0] == all) f[s] = max(f[s], f[s^s0] + 1);
}
}
cout<<"Case "<<++kase<<": "<<f[all]<<endl;
}
}