Exercises
The first pressure DP problem. So write it carefully.
The title translates to:
There are n sets grouped to find the number of groups that satisfy the condition
The status is: N sets, with each collection selected or not selected. A total of 1<<n species
According to the binary, can be pushed forward backwards F[s]=max (F[s-s0]) +1, S0 is a subset of S, Cover[s0] equals the complete
Subset enumeration:
for (int x = S; x; x = (x1) &s)
Explain
Http://www.cnblogs.com/jffifa/archive/2012/01/16/2323999.html
(x-1) &s 0 of S is ignored, and the result is continuously reduced by 1
Code:
#include <bits/stdc++.h>using namespacestd;Const intmaxn=1<< -;intN,m,x,all,case=1;intcover[maxn],f[maxn],p[ -];intMain () { while(~SCANF ("%d", &n) &&N) { for(intI=0; i<n;i++) {P[i]=1<<i; scanf ("%d",&m); while(m--) {scanf ("%d",&x); P[i]|=(1<<X);//The collection of each point and the adjacent point is represented by a binary, with n points, so there are n sets}} All=(1<<n)-1; for(ints=0;s< (1<<N); s++) {Cover[s]=0; for(intI=0; i<n;i++) { if(s& (1<<i)) Cover[s]|=p[i];//s represents the selected set of binary and, cover[s] to indicate how many points are selected for these collections, and the binary representation } } for(ints=0;s< (1<<N); s++) {F[s]=0; for(intS0=s;s0;s0= (s0-1) &s)//S0 as a subset of S { if(Cover[s0]==all) F[s]=max (f[s],f[s^s0]+1); }} printf ("Case %d:%d\n", case++, F[all]); } return 0;}
UVA11825 Hackers ' crackdown