UVA11825 Hackers ' crackdown

Source: Internet
Author: User

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&LT;&LT;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&LT;&LT;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&LT;&LT;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

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.