zoukankan      html  css  js  c++  java
  • [Uva 11825] Hackers’ Crackdown

    Hackers’ Crackdown 

    Input: Standard Input

    Output: Standard Output

     

    Miracle Corporations has a number of system services running in a distributed computer system which is a prime target for hackers. The system is basically a set of computer nodes with each of them running a set of 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 that service in all the nodes.

    One day, a smart hacker collects necessary exploits for all these 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 have the characteristic that, its successfully infects the computer where it was 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 will be multiple test cases in the input file. A test case begins with an integer N (1<=N<=16), the number of nodes in the network. The nodes are denoted by 0 to N - 1. Each of the following lines describes the neighbors of a node. Line i (0<=i<N) represents the description of node i. The description for node starts with an integer (Number of neighbors for node i), followed by integers in the range of to N - 1, each denoting a neighboring node of node i.

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

    Output

    For each test case, print a line in the format, “Case X: Y”, where X is the case number & Y is the maximum possible number of services that can be damaged.

    Sample Input

    1 3 6 7
    1 7 5 4 8 3 9
    1 4 3 5 6 2 8 9

    Sample Output

    Case 1: 3
    Case 2: 2

     状压DP、枚举子集

    #include <iostream>
    #include <cstring>  
    #include <cstdio>
    using namespace std;  
    #define N (1<<16)+10
    
    int n;
    int p[20];
    int cover[N];
    int dp[N];
    
    int main()  
    {
        int i,j,k,iCase=1;
        while(scanf("%d",&n),n)
        {
            for(i=0;i<n;i++)
            {
                int m,x;
                p[i]=1<<i;
                scanf("%d",&m);
                while(m--)
                {
                    scanf("%d",&x);
                    p[i]|=(1<<x);
                }
            }
            int MAX=1<<n;
            for(j=0;j<MAX;j++)
            {
                cover[j]=0;
                for(i=0;i<n;i++)
                {
                    if(j&(1<<i)) cover[j]|=p[i];
                }
            }
            for(j=0;j<MAX;j++)         //枚举集合j
            {
                dp[j]=0;
                for(k=j;k;k=(k-1)&j)   //枚举子集k
                {
                    if(cover[k]==MAX-1) dp[j]=max(dp[j],dp[j^k]+1);
                }
            }
            printf("Case %d: %d
    ",iCase++,dp[MAX-1]);
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    Alink漫谈(五) : 迭代计算和Superstep
    Alink漫谈(四) : 模型的来龙去脉
    Elasticsearch索引模板-转载
    Filebeat配置文件解析-转载
    Logtash 配置文件解析-转载
    Logtash遇到的异常和注意点
    Linux中Sshd服务配置文件优化版本(/etc/ssh/sshd_config)
    运维应急方案撰写-草稿版分享
    du和df的统计结果为什么会不一样?
    全网最详细的Linux命令系列-Screen远程会话命令
  • 原文地址:https://www.cnblogs.com/hate13/p/4136179.html
Copyright © 2011-2022 走看看