UVA 11825(Hacker's Crackdown-集合)
原创
©著作权归作者所有:来自51CTO博客作者mb62d7cd05038ca的原创作品,请联系作者获取转载授权,否则将追究法律责任
给一个集合U和一堆子集
最多把子集分成多少份,使每份的并为全集U?
集合子集的遍历 for(int S0 = S; S0; S0 = (S0-1)&S)
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
int f[1<<17],P[1<<17],cover[1<<17];
int main()
{
// freopen("uva11825.in","r",stdin);
// freopen(".out","w",stdout);
int n,kcase=1;
while (n=read()) {
int ALL=(1<<n)-1;
Rep(i,n) {
P[i]=1<<i;
int m=read();
while (m--) P[i]|=1<<( read() );
}
Rep(S,1<<n) {
cover[S] = 0;
Rep(i,n) if (S & (1<<i) ) cover[S]|=P[i];
}
Rep(S,1<<n) {
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);
}
printf("Case %d: %d\n",kcase++,f[ALL]);
}
return 0;
}