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
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- Using namespace std;
- int n,m,pow2[20],val[20],c[100010],dp[100010];
- int main ()
- {
- int t=0,i,j,k,total;
- Pow2[0]=1;
- For (i=1;i<=16;i++)
- pow2[i]=pow2[i-1]*2;
- while (~scanf ("%d", &n) && n>0)
- {
- For (i=0;i<n;i++)
- {
- Val[i]=pow2[i];
- scanf ("%d", &m);
- For (j=1;j<=m;j++)
- {
- scanf ("%d", &k);
- VAL[I]+=POW2[K];
- }
- }
- Total=pow2[n]-1;
- For (i=1;i<=total;i++)
- {
- c[i]=0;
- For (j=0;j<n;j++)
- if (I&pow2[j])
- C[I]|=VAL[J];
- }
- For (i=1;i<=total;i++)
- {
- dp[i]=0;
- For (k=i;k>0;k= (k-1) &i)
- if (c[k]==total)
- Dp[i]=max (dp[i],dp[i^k]+1);
- }
- printf ("Case%d:%d\n", ++t,dp[total]);
- }
- }
Hackers ' crackdown-uva11825 pressure DP