Title: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18913
This problem is a good problem of the state compression DP, there are a few points to note:
1.uva given the topic do not know why, test instructions is some of the description is unclear, see "Training Guide"
2. The problem can be written in many way, the whole DP solution and cover that part can write as a memory search from top to bottom, can also be achieved from the end.
#include <cstdio>#include<iostream>#include<cstring>using namespacestd;/*State transfer equation: dp[s] = max (dp[s-s ']+1) if cover (S ') = = All*/Const intMAXN =1<< -+5;intA[MAXN], DP[MAXN], C[MAXN];intAll ;intMain () {intN, M, X, kase=1; while(SCANF ("%d", &n)! = EOF &&N) { for(intI=0; i<n; i++) {scanf ("%d", &m); A[i]=1<<i; for(intj=0; j<m; J + +) {scanf ("%d", &x); A[i]|=1<<x; }} All= (1<<n)-1; for(intI=1; i<=all; i++) {C[i]=0; intS = i, cur =0; while(S) {if(s&1) {C[i]|=A[cur]; } cur++; S>>=1; } } for(ints=1; s<=all; s++) {Dp[s]=0; for(intS=s; S s = (s1) {&s) {//Here the initial s can be taken to S if(c[s]==All ) {Dp[s]= Max (dp[s^s]+1, Dp[s]); }}} printf ("Case %d:%d\n", kase++, Dp[all]); } return 0;}
Uva-11825--hackers ' crackdown