11825 - Hackers' Crackdown uva

本文探讨了一个复杂的网络系统面临的黑客攻击问题,系统由多个节点组成,每个节点运行相同的服务。文章介绍了一种算法,用于计算黑客利用特定漏洞能破坏的最大服务数量,并提供了一个示例程序来解决这一挑战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 m (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

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


个人认为有难度的一道题:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
int p[20];
int cover[100000];
int f[100000];
int main()
{
    int n;
    int kcase = 0;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;
        kcase++;
        for(int i = 0;i<n;++i)//输入处理
        {
            int m,x;
            scanf("%d",&m);
            p[i] = (1<<i);//第i个计算机是每个子集的一个元素
            while(m--)
            {
                scanf("%d",&x);
                p[i] |= (1<<x);//将每个元素按位或得到并集形成第i个子集(子集用整数表示)
            }
        }


        for(int s = 0;s<(1<<n);++s)//共有1<<n个子集..对于给定的s集合中所有p[i]的并集
        {
            cover[s] = 0;
            for(int i= 0;i<n;++i)//第s个集合中共有哪些上述子集
            {
                if(s & (1<<i))
                cover[s] |= p[i];//对于给定的s集合中所有p[i]的并集
            }
        }

        f[0] = 0;
        int ALL = (1<<n)-1;//全集
        for(int s = 1;s<(1<<n);++s)
        {
            f[s]=0;//f[s]表示集合s最多可以分成多少组
                  //那么f[s] = max{f[s0]|s0是s的子集,cover[s0]为全集}+1
            for(int s0=s;s0!=0;s0 = (s0-1)&s)//枚举s的子集s0...只有当(s0-1)&s时s0-1才是s的子集
                                            //子集与全集一定有公共元素
              if(cover[s0]==ALL)
              f[s] = max(f[s],f[s^s0]+1);//
        }
        printf("Case %d: %d\n",kcase,f[ALL]);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值