uva 11825 Hackers' Crackdown(动态规划-状态压缩DP)
来源:互联网 发布:php判断蜘蛛 编辑:程序博客网 时间:2024/06/05 16:15
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 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
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
Problemsetter: Mohammad Mahmudur Rahman
Special Thanks Manzurur Rahman Khan
题目大意:
有n台计算机,每台计算机运行n个不同进程,现在你可以每台机器上停止一个服务,而且你停止了1台机器上的这个服务的同时,其相连机器上的这个服务也会停止,再告诉 你每台机器相连的机器,当一个所有机器上的这个服务都停止了,那么这个服务才算没有被运行,问你最多多少个服务没有 被运行?
解题思路:
其实就是把这些机器分成最多的子集合集合,每个子集合合并起来能够影响全部,这样就能解决问题。这样枚举的状态就是2^16次方。
解题代码:
#include <iostream>#include <cstdio>using namespace std;const int maxn=(1<<16)+10;int n,all,dp[maxn],a[maxn],value[maxn];void initial(){ all=(1<<n)-1; for(int i=0;i<=all;i++) dp[i]=-1;}void input(){ for(int i=0;i<n;i++){ int m,x; scanf("%d",&m); a[i]=(1<<i); while(m-- >0){ scanf("%d",&x); a[i]|=(1<<x); } } for(int i=0;i<=all;i++){ value[i]=0; for(int t=0;t<n;t++){ if( i&(1<<t) ){ value[i]|=a[t]; } } }}int DP(int sum){ if(value[sum]!=all ) return 0; if(dp[sum]!=-1) return dp[sum]; int ans=0; for(int x=sum;x!=0;x=(x-1)&sum ){ if(value[x]==all){ if(1+DP(sum-x)>ans) ans=1+DP(sum-x); } } return dp[sum]=ans;}int main(){ int casen=0; while(scanf("%d",&n)!=EOF && n!=0 ){ initial(); input(); printf("Case %d: %d\n",++casen,DP(all) ); } return 0;}
- uva 11825 Hackers' Crackdown(动态规划-状态压缩DP)
- Uva 11825 - Hackers’ Crackdown 状态压缩DP
- UVA 11825 Hackers' Crackdown 状态压缩dp
- UVa 11825 Hackers’ Crackdown / 状态压缩DP
- UVA 11825 - Hackers' Crackdown(dp+状态压缩)
- UVA 11825 Hackers' Crackdown DP+状态压缩 -
- UVa 11825 Hackers' Crackdown (状态压缩DP)
- Uva - 11825 - Hackers' Crackdown(状态压缩dp)
- UVA 11825 - Hackers' Crackdown(状态压缩DP)
- UVA 11825 Hackers' Crackdown(状态压缩DP)
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
- Uva 11825 - Hackers' Crackdown 状态压缩
- UVA - 11825 Hackers' Crackdown 状态压缩
- UVa 11825 Hackers' Crackdown(二进制压缩+DP)
- 【动态规划】[UVa 11825]Hackers' Crackdown
- UVA 11825Hackers' Crackdown dp+位运算状态压缩(子集枚举)
- UVA 11825 Hackers' Crackdown(状压dp)
- UVA 11825 Hackers' Crackdown (dp)
- 中文Ubuntu里用户目录里的路径改成英文
- Fragment报java.lang.IllegalArgumentException:No view found for id 0x7f070250的错误
- iOS后台播放音乐
- hdu 2830 Matrix Swapping II (dp+树状数组)
- Epydoc——Python文档化开发注释规范化工具
- uva 11825 Hackers' Crackdown(动态规划-状态压缩DP)
- 八皇后问题
- Ubuntu12.04 不能启动,显示 "Could not write bytes: broken pipe"
- WWDC:苹果走向开放和封闭的极端
- centos 6 配置yum
- Spin Lock -- TAS和TTAS
- 远程登录CentOS,短时间就断线的处理
- 频域时域关系
- mysql数据库基本操作(一)