UVA 11825 Hackers' Crackdown

题目

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 N computer nodes with each of 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 that 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 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
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 an integer m (Number of neighbors for node i), followed by m
integers in the range of 0 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
3
2 1 2
2 0 2
2 0 1
4
1 1
1 0
1 3
1 2
0
Sample Output
Case 1: 3
Case 2: 2

大意

有n台服务器,每个服务器上运行n个服务,有个黑客想去毁掉尽可能多的服务,黑客只能在每台服务器上毁掉某一个服务,同时和这台服务器直接相连的服务器的这个服务也会被毁掉,某个服务要在每个服务器上都毁掉了才算毁掉了,求最多能毁掉的服务。

解法

用i表示服务器的一个状态,i的二进制下某位是1表示黑客在这台服务器上毁掉了某个服务,0则没有,设f[i]=1表示i这个状态能毁掉一个服务,0则表示不行,然后还要排除一些多余的,比如f[101]是1,那么f[111]肯定是1了,但是既然能用少量的肯定会有少量的,所以f[111]是不应该被用到的,应该置为0。最后设dp[i]表示状态为i时的最大值,就有
if(f[j]==1&&(i&j)==j)
dp[i]=max(dp[i],1+dp[i^p[j]]);
答案就是dp[1<<n];

代码

#include<cstdio>
#include<cstring>
int a[20][20],cnt[20],f[70000],vis[20],dp[70000],p[70000],cn;
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	int n,i,j,cas=1;
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&cnt[i]);
			for(j=0;j<cnt[i];j++)
			{
				scanf("%d",&a[i][j]);
			}
		}
		int lim=(1<<n);
		memset(f,0,sizeof(f));
		f[0]=0;
		for(i=1;i<lim;i++)
		{
			memset(vis,0,sizeof(vis));
			int tmp=i,pos=0;
			while(tmp)
			{
				if(tmp&1)
				{
					vis[pos]=1;
					for(j=0;j<cnt[pos];j++)
						vis[a[pos][j]]=1;
				}	
				tmp=tmp>>1;
				pos++;
			}	
			for(j=0;j<n;j++)
				if(vis[j]==0)
					break;
			if(j==n)
				f[i]=1;
		}
		cn=0;
		for(i=1;i<lim;i++)
		{
			if(f[i]==0)
				continue;
			p[cn++]=i;
			for(j=i+1;j<lim;j++)
			{
				if((j&i)==i)
				{
					f[j]=0;
				}
			}
		}
		memset(dp,0,sizeof(dp));
		for(i=1;i<lim;i++)
		{
			for(j=0;j<cn;j++)
			{
				if((i&p[j])==p[j])
				{
					dp[i]=max(dp[i],1+dp[i^p[j]]);
				}
			}	
		}
		printf("Case %d: %d\n",cas++,dp[lim-1]);
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值