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 computer nodes with each of them running a set of Nservices. 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

3

2 1 2

2 0 2

2 0 1

4

1 1

1 0

1 3

1 2

0

Output for Sample Input

Case 1: 3

Case 2: 2

题意:

(黑客的攻击)假设你是一个黑客,侵入了了一个有着n台计算机(编号为0,1,…,n-1)的网络。一共有n种服务,每台计算机都运行着所有的服务。对于每台计算机,你都可以选择一项服务,终止这台计算机和所有与它相邻计算机的该项服务(如果其中一些服务已经停止,则这些服务继续处于停止状态)。你的目标是让尽量多的服务器完全瘫痪(即:没有任何计算机运行该项服务)

题解:

    先把每个点集能覆盖到的电脑cover预处理出来。然后枚举每个状态,枚举每个状态的子集,如果该子集能覆盖到全部,状态转移就+1。

状态转移方程 dp[state] = dp[state - substate] + (substate == ((1<<n) - 1));

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = , M = , mod = 1e9+, inf = 0x3f3f3f3f;
typedef long long ll;
//不同为1,相同为0 int dp[<<N],c[<<N],x,n,cas = , point[<<N];
int main() {
while(scanf("%d",&n) == && n) {
for(int i=;i<n;i++) {
scanf("%d",&x);int j;
point[i] = (<<i);
while(x--) scanf("%d",&j), point[i]|=(<<j);
}
for(int i=;i<(<<n);i++) {
c[i] = ;
for(int j=;j<n;j++) {
if(i&(<<j)) c[i]|=point[j];
}
}
for(int i=;i<(<<n);i++) {
dp[i] = ;
for(int j=i;j;j = (j-)&i) {
if(c[j] == (<<n) - ) dp[i] = max(dp[i], dp[i^j] + );
}
}
printf("Case %d: %d\n", ++cas, dp[(<<n) - ]);
}
}

UVA 11825 Hackers’ Crackdown 状压DP枚举子集势的更多相关文章

  1. UVa 11825 Hackers' Crackdown (状压DP)

    题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务. 析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的 ...

  2. [Luogu P3959] 宝藏 (状压DP+枚举子集)

    题面 传送门:https://www.luogu.org/problemnew/show/P3959 Solution 这道题的是一道很巧妙的状压DP题. 首先,看到数据范围,应该状压DP没错了. 根 ...

  3. 计蒜客习题:蒜头君的积木 (状压DP 枚举子集)

    问题描述 蒜头君酷爱搭积木,他用积木搭了 n 辆重量为 wi的小车和一艘最大载重量为 W 的小船,他想用这艘小船将 n 辆小车运输过河.每次小船运载的小车重量不能超过 W.另外,小船在运载小车时,每辆 ...

  4. BZOJ 2560: 串珠子 (状压DP+枚举子集补集+容斥)

    (Noip提高组及以下),有意者请联系Lydsy2012@163.com,仅限教师及家长用户. 2560: 串珠子 Time Limit: 10 Sec Memory Limit: 128 MB Su ...

  5. UVA11825 黑客的攻击 Hackers' Crackdown 状压DP,二进制,子集枚举

    题目链接Click Here [题目描述] 假如你是一个黑客,侵入了一个有着\(n\)台计算机(编号为\(1.2.3....n\))的网络.一共有\(n\)种服务,每台计算机都运行着所有服务.对于每台 ...

  6. [UVA11825]Hackers' Crackdown(状压dp)

    题解降智警告 吐槽降智警告 思路降智警告 代码降智警告 题目传送门 洛谷 果然水题做多了连半道难点的都能给咱干蒙... 水题做多了降智  --鲁迅 题目大意:见传送门 心路历程见末尾 正解(大概): ...

  7. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  8. [Uva 11825] Hackers’ Crackdown

    Hackers’ Crackdown  Input: Standard Input Output: Standard Output   Miracle Corporations has a numbe ...

  9. HDU 5657 CA Loves Math 状压DP + 枚举

    题意: 给出\(A(2 \leq A \leq 11), n(0 \leq n \leq 10^9), k(1 \leq k \leq 10^9)\). 求区间\([1, A^n]\)中各个数字互不相 ...

随机推荐

  1. 数组map方法与如何使用ES5实现

    数组map方法与如何使用ES5实现 JavaScript Array map() 方法 定义 map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值. map() 方法按照原始数 ...

  2. C# 常用代码片段

    一.从控制台读取东西代码片断: using System; class TestReadConsole { public static void Main() { Console.Write(Ente ...

  3. WPF 漏斗控件 等待沙漏效果

    由于WPF中不支持gif图片因此要实现一个漏斗沙漏效果有点小麻烦. 网上有一款开源的控件 理论上完全开源 官网 http://wpfspark.codeplex.com/贴一下效果图 大家感觉需要就在 ...

  4. html中map标签和area标签的应用

    map标签的用途:是与img标签绑定使用的,常被用来赋予给客户端图像某处区域特殊的含义,点击该区域可跳转到新的文档. 因为map标签是与img标签绑定使用的,所以我们需要给map标签添加ID和name ...

  5. 转/ C# 托管资源和非托管资源

    原文 对于这两个一直就是模模糊糊的,半知零解 托管资源指的是.NET可以自动进行回收的资源,主要是指托管堆上分配的内存资源.托管资源的回收工作是不需要人工干预的,由.NET运行库在合适时调用垃圾回收器 ...

  6. Oracle中的SAVEPOINT

    学习存储过程中使用断点回滚事务时,发现目前网络上存在一个问题,那就是使用断点回滚后,都忘记了一个很重要的事情,提交事务.虽然使用了断点回滚,但是断点回滚不像rollBack或commit一样结束当前事 ...

  7. 命令行 RSA, Base64, Hash

    序 # -n 可以去掉换行符 echo -n '777777' RSA算法 加密 # 利用管道命令传递字符串加密 echo -n '777777' | openssl rsautl -encrypt ...

  8. 信息检索及DM必备知识总结:luncene

    原文链接:http://blog.csdn.net/htw2012/article/details/17734529 有少量修改!如有疑问,请访问原作者. 一:信息检索领域: 信息检索和网络数据领域( ...

  9. poj 2955 Brackets 【 区间dp 】

    话说这题自己折腾好久还是没有推出转移的公式来啊------------------ 只想出了dp[i][j]表示i到j的最大括号匹配的数目--ค(TㅅT)------------------- 后来搜 ...

  10. 开发一个 App 有多难?说出来你可能不信!

    上图为程序员客栈儿童类视频APP 1.开发一个APP有多难?说实话,单纯地从开发来说,开发一个APP没有那么难.如果一款APP的基本功能点确定了,开发时间一般为1-2个月就完成了,费用大约5-10万的 ...