Uva-11825--hackers ' crackdown

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.