The problem of test instructions is that there are n computers, each computer has n services, and then each computer and a few computers next to each other, there is a hacker can stop a service on each computer, and then this computer and the computer adjacent to it will stop, ask the maximum number of services can be stopped.
The problem is to put the relationship between computers into a set, because the range of n is smaller, so can state compression, with (1<<n)-1 represents the complete computer, and then each computer and its adjacent computer can be used p[i] binary record, and then open a cover array, subscript to take a subset of the complete set , look at the subsets of these computers plus their neighboring computers, meaning to stop a service on the selected computers, plus the computers they affect, can cover the entire collection (n computers).
State transfer F[s]=max (F[S-S0]) +1,S0 is a subset of S, cover[s0]= complete.
#include <iostream> #include <cstdio> #include <cctype> #include <cstdlib> #include <cmath > #include <algorithm> #include <cstring> #include <string> #include <vector> #include <
queue> #include <map> #include <set> #include <sstream> #include <stack> using namespace std;
#define MAX, a typedef long long LL;
const double pi=3.141592653589793;
const int INF=1E9;
const double INF=1E20;
const double eps=1e-6;
int cover[70000],f[70000];
int main () {int n,m,x,kase=0;
int p[20];
while (cin>>n&&n) {kase++;
for (int i=0;i<n;i++) {cin>>m;
P[i]= (1<<i);
while (m--) {cin>>x;
P[i]|= (1<<X);
}} for (int s=0;s< (1<<n); s++) {cover[s]=0;
for (int i=0;i<n;i++) {if (s& (1<<i)) cover[s]|=p[i];
}} f[0]=0;
int all= (1<<n)-1;
for (int s=0;s<=all;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);
}} printf ("Case%d:%d\n", Kase,f[all]);
} return 0;
}