【UVA11825】Hackers' Crackdown
来源:互联网 发布:中行外汇分析软件 编辑:程序博客网 时间:2024/06/05 22:17
题意
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.
题面
有
n 个节点,每一个节点都有n 种标记,现在可以对每一个节点分别进行一次操作,每一次操作可以选择一种标记,使这个节点及与其相邻的节点覆盖这种标记(一个节点可以被覆盖多种标记),问经过n 操作后,最多有多少种标记覆盖了所有节点
n≤16 ,节点编号从0开始
解法
子集
DP :
第一次做子集DP 的题……
这个题目的意思就是说:全集为U ,|U|=n ,有n 个集合,为{P1,P2……Pn },现在要对这n 个集合进行分组,要求P1∪P2∪……∪Pk=U ,P 为该组内的集合,求最多能分多少组
设stai 为一个二进制数,表示第i 个节点相邻的点及自身,例如i=10 (2),stai=10110 (2),表示与1号节点相邻的有4,2两个节点。由此可知,stai 表示对i 进行操作能够标记的点的集合
设pi 表示选择i 表示的集合能够标记的点集,i 为一个二进制数,例如i=10010 (2)表示选择{0,4}这个集合能够标记的点集
设fi 表示选择i 集合能够标记的全集个数,即答案,i 也是一个二进制数。状态已经设出来了,下面就是如何转移:
对于一种状态i ,i 表示的就是一个集合,考虑如何枚举出i 的所有子集,可以参见刘汝佳的紫书
复杂度
O(
2n *平均非空子集个数),当有n 个物品时,总非空子集数为:∑ni=1Cin
代码
#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#define Lint long long intusing namespace std;const int N=20;const int L=(1<<17);int f[L+5],p[L+5];int sta[N];int n,A;int main(){ int len,x,C=0; while( scanf("%d",&n) && n ) { memset( sta,0x0,sizeof sta ); memset( f,0x0,sizeof f ),memset( p,0x0,sizeof p ); for(int i=0;i<=n-1;i++) { scanf("%d",&len); for(int j=1;j<=len;j++) { scanf("%d",&x); sta[i]|=(1<<x); } sta[i]|=(1<<i); } A=(1<<n)-1; for(int i=0;i<=A;i++) { p[i]=0; for(int j=0;j<=n-1;j++) if( i&(1<<j) ) p[i]|=sta[j]; } for(int i=0;i<=A;i++) { if( p[i]!=A ) f[i]=0; else f[i]=1; for(int j=i; j ;j=(j-1)&i) f[i]=max( f[i],f[j]+f[i^j] ); } printf("Case %d: %d\n",++C,f[A]); } return 0;}
- uva11825 Hackers' Crackdown
- Uva11825 - Hackers' Crackdown
- uva11825 - Hackers' Crackdown
- UVa11825 Hackers' Crackdown
- 【UVA11825】Hackers' Crackdown
- UVa11825 Hackers' Crackdown
- Hackers’ Crackdown - UVa11825 状压dp
- UVA11825[Hackers' Crackdown] 动态规划
- Hackers’ Crackdown-----UVA11825-----DP+状态压缩
- uva11825 - Hackers' Crackdown(状态压缩dp)
- UVA11825: Hackers' Crackdown (状压dp)
- 例题29 UVa11825 Hackers' Crackdown(DP:子集)
- Hackers' Crackdown
- Uva-11825-Hackers’ Crackdown
- UVA 11825 Hackers' Crackdown
- UVA 11825 Hackers' Crackdown
- uva 11825 - Hackers' Crackdown
- UVA - 11825 Hackers' Crackdown
- YUV图像格式
- java操作hive2.1.0
- linux的常用命令
- 简单的二分算法
- 写点东西简单理解 javascript 的正则表达式
- 【UVA11825】Hackers' Crackdown
- VMware linux系统扩展磁盘
- opencv 3.0 填充矩形 填充多边形 fillPoly
- html之marquee 详解
- 每位程序员必读的书单
- 各国际会议的影响因子
- vmware 虚拟化Intel VT-x/EPT选项
- 4-20ma输出电路
- 工具:为GitHub 添加SSH-key简介