Hackers ' crackdown-uva11825 pressure DP

Source: Internet
Author: User

Problem H

Hackers ' crackdown
Input:
standard input

Output: Standard Output

Miracle corporations have a number of system services running in a distributed computer system which are a prime target for Hackers. The system is basically a set of n computer nodes with each of the them running a set of N services. Note that, the set of services running on every node is same everywhere in the network. A hacker can destroy a service by running a specialized exploit for this service in all the nodes.

One day, a smart hacker collects necessary exploits for all these N services and launches an attack on the system . He finds a security hole that gives him just enough time to run a single exploit in each computer. These exploits has the characteristic, its successfully infects the computer where it is originally run and all the Neighbor computers of that node.

Given A network description, find the maximum number of services that the hacker can damage.

Input

There'll is multiple test cases in the input file. A test case is begins with an integer N (1<=n<=16)and the number of nodes in the network. The nodes is denoted by 0 to N-1. Each of the following N lines describes the neighbors of a node. Line I (0<=i<n)represents the description of node I. The description for node I starts with a integer m (number of neighbors for node i), followed bym integers in the range of 0 to N-1, each denoting a neighboring node of node I.

The end of input would be denoted by a case with N = 0. This case is should not being processed.

Output

For each test case, print a line in the format, ' casex:y', where X is the case number & Y is the maximum possible number of services can damaged.

Sample Input

Output for Sample Input

3

2 1 2

2 0 2

2 0 1

4

1 1

1 0

1 3

1 2

0

Case 1:3

Case 2:2

Test instructions: There are n computers that perform 1-n projects together, and for each computer you have a chance to make it impossible to work on a project while the computer with which it is directly connected has received the impact. If a project is not implemented by a computer, the project will be paralyzed, and the maximum number of projects can be paralysed.

Idea: The first day of the computer and its direct connection to the first form of pressure, indicating which paralysis. S represents the maximum number of damaged works that have been paralyzed by the current computer, so Dp[s]=max (dp[s],dp[s2]+1) If S-S2 can paralyze a project. Here is also a subset of the implementation techniques see Code.

The AC code is as follows:

[CPP]View Plaincopy
    1. #include <cstdio>
    2. #include <cstring>
    3. #include <algorithm>
    4. Using namespace std;
    5. int n,m,pow2[20],val[20],c[100010],dp[100010];
    6. int main ()
    7. {
    8. int t=0,i,j,k,total;
    9. Pow2[0]=1;
    10. For (i=1;i<=16;i++)
    11. pow2[i]=pow2[i-1]*2;
    12. while (~scanf ("%d", &n) && n>0)
    13. {
    14. For (i=0;i<n;i++)
    15. {
    16. Val[i]=pow2[i];
    17. scanf ("%d", &m);
    18. For (j=1;j<=m;j++)
    19. {
    20. scanf ("%d", &k);
    21. VAL[I]+=POW2[K];
    22. }
    23. }
    24. Total=pow2[n]-1;
    25. For (i=1;i<=total;i++)
    26. {
    27. c[i]=0;
    28. For (j=0;j<n;j++)
    29. if (I&pow2[j])
    30. C[I]|=VAL[J];
    31. }
    32. For (i=1;i<=total;i++)
    33. {
    34. dp[i]=0;
    35. For (k=i;k>0;k= (k-1) &i)
    36. if (c[k]==total)
    37. Dp[i]=max (dp[i],dp[i^k]+1);
    38. }
    39. printf ("Case%d:%d\n", ++t,dp[total]);
    40. }
    41. }

Hackers ' crackdown-uva11825 pressure DP

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.