UVA 11825 Hackers' Crackdown

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <utility>
using namespace std;

#define rep(i,j,k) for (int i=j;i<=k;i++)
#define Rrep(i,j,k) for (int i=j;i>=k;i--)

#define Clean(x,y) memset(x,y,sizeof(x))
#define LL long long
#define ULL unsigned long long
#define inf 0x7fffffff
#define mod 100000007

const int maxn = 1<<16;
int a[20];
int s[maxn];
bool can[maxn+10];
int dp[maxn+10];
int n,uplim;

void init()
{
int m,temp;
uplim = (1<<n) - 1;
rep(i,1,n)
{
a[i] = 1<<(i-1);
scanf("%d",&m);
rep(j,1,m)
{
scanf("%d",&temp);
a[i] |= 1<<temp;
}
}
}

int solve()
{
Clean(can,false);
rep(i,1,uplim)
{
s[i] = 0;
rep(j,0,n-1)
if ( i & (1<<j) )
s[i] |= a[j+1];
}
rep(i,1,uplim)
{
can[i] = s[i] == uplim;
for ( int j = (i - 1) & i; j; j = (j - 1) & i )
can[i] = ( s[j] | s[i-j] ) == uplim;
if ( can[i] )
dp[i] = 1;
else dp[i] = 0;
}
rep(i,1,uplim)
{
for ( int j = (i - 1) & i; j; j = (j - 1) & i )
dp[i] = max( dp[i] , dp[j] + dp[i-j] );
}
return dp[uplim];
}
int main()
{
int kase = 0;
while(cin>>n)
{
if ( !n ) break;
init();
printf("Case %d: %d\n",++kase,solve());
}
return 0;
}


02-05 481

12-05 536

12-24 166

09-20 1157

04-06 608

04-22 54

07-15 267

08-10 102

06-03 669

01-28 1172