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

题解:

  这个题目首先把模型抽象出来,n个集合,将每个集合分组,使得每组集合元素的并的于全集,求最多可以分成多少组。

  首先集合有关,我们数据范围16,我们首先想到子集dp,设dp[S],表示集合S中各个元素的并等于全集的数量,那么转移十分好转dp[S]=dp[S-S次]+1,S次 是S的子集,且S次的并等于全集。

  但实现起来还是十分麻烦,首先我们可以用二斤制压缩来表示一个电脑集合p[i],p[now]|=1<<x;其次就是集合取并集,我们用“|”来实现,就是如果包括这个元素i那么就|=p[i],最后是枚举子集,枚举集合S的子集S0我们可以for(int s0=s;s0;s0=(s0-1)&s),这个还比较玄学吧。

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#define MAXN 20
using namespace std;
int n,m;
int dp[<<MAXN],cover[<<MAXN],p[MAXN]; void cl(){
memset(p,,sizeof(p));
memset(dp,,sizeof(dp));
memset(cover,,sizeof(cover));
} int main(){
int ca=;
while(){
cl();
scanf("%d",&n);
if(!n) break;
for(int now=;now<n;now++){
scanf("%d",&m);
for(int i=;i<=m;i++){
int x;scanf("%d",&x);
p[now]|=<<x;
}
p[now]|=<<now;
}
int all=(<<n)-;
for(int s=;s<=all;s++){
for(int i=;i<n;i++)
if(s&(<<i)) cover[s]|=p[i];
}
for(int s=;s<=all;s++){
for(int s0=s;s0;s0=(s0-)&s){
if(cover[s0]==all) dp[s]=max(dp[s],dp[s^s0]+);
}
}
printf("Case %d: %d\n",++ca,dp[all]);
}
}

Hackers' Crackdown UVA - 11825的更多相关文章

  1. Hackers' Crackdown UVA - 11825 (状压dp)

    给出n个电脑,每个电脑连着n个服务,然后每个电脑都连着m个邻电脑,如果当前的电脑某个服务被断开了,相邻的电脑的服务也会被断开,每个电脑都只能操作一次,问你最多可以让多少种服务被断开.一种服务被断开的条 ...

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

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

  3. UVA 11825 Hackers' Crackdown

    题目大意就是有一个图,破坏一个点同时可以破坏掉相邻点.每个点可以破坏一次,问可以完整破坏几次,点数=16. 看到16就想到状压什么的. 尝试设状态:用f[i]表示选的情况是i(一个二进制串),至少可以 ...

  4. [Uva 11825] Hackers’ Crackdown

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

  5. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  6. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  7. UVA 11825 Hackers’ Crackdown 状压DP枚举子集势

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  8. UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

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

    这是我做状压DP的第一道题,状压里面都是用位运算来完成的,只要耐下心来弄明白每次位运算的含义,还是容易理解的. 题意: 有编号为0~n-1的n台服务器,每台都运行着n中服务,每台服务器还和若干台其他服 ...

随机推荐

  1. Scrum团队的最佳规模?

    无论你在小型创业公司工作还是在大公司的新产品线工作,当团队人数越来越多时总会达到一个临界点.尽早识别这个临界点可以让您的团队避免进入低效阶段.每个产品都是不同的,团队合作也是如此.因此,拆分团队也需要 ...

  2. [系列] go-gin-api 路由中间件 - Jaeger 链路追踪(五)

    概述 首先同步下项目概况: 上篇文章分享了,路由中间件 - 捕获异常,这篇文章咱们分享:路由中间件 - Jaeger 链路追踪. 啥是链路追踪? 我理解链路追踪其实是为微服务架构提供服务的,当一个请求 ...

  3. Linux 笔记 - 第八章 文档的打包与压缩

    博客地址:http://www.moonxy.com 一.前言 在 Linux 系统中,文件的后缀名没有实际的意义,加或者不加都无所谓.但是为了便于区分,我们习惯在定义文件名时加一个后缀名,比如常见的 ...

  4. sys模块理解补充

    首先,我们利用import语句输入sys模块.基本上这句话告诉python,我们想要这个模块.sys模块包含了与python解释器和它的环境有关的函数. 当python执行import sys语句的时 ...

  5. linux 堆栈查看

    top -c 查看进程ID pstree PID 查看线程树 pstack PID 查看堆栈

  6. Centos利用脚本自动安装jdk

        在工作中还有自己的学习中,无论是使用tar包安装jdk,还是使用rpm安装,如果单台机器还能够接受,但是如果多台机器,就很困扰.所以,在自己配置环境的时候,根据网上各位前辈,沉淀了这样子一个脚 ...

  7. C# 反射基础用法

    1.引用命名空间 using System.Reflection; 2.object[] parameters = { 参数 }; 调用方法的参数数组 3.Type t = Type.GetType( ...

  8. 检查图片是否损坏、图片后缀是否与实际图片类型对应 - Python

    图片工具 检查图片是否损坏 日常工作中,时常会需要用到图片,有时候图片在下载.解压过程中会损坏,而如果一张一张点击来检查就太不Cool了,因此我想大家都需要一个检查脚本: 测试图片,0.jpg是正常的 ...

  9. 为何stop()和suspend()方法不推荐使用(转)

    stop()方法作为一种粗暴的线程终止行为,在线程终止之前没有对其做任何的清除操作,因此具有固有的不安全性. 用Thread.stop()方法来终止线程将会释放该线程对象已经锁定的所有监视器.如果以前 ...

  10. 前端使用lodop插件进行打印设置

    先前梳理了后台打印导出参考:https://www.cnblogs.com/yyk1226/p/9856032.html,但是没有显示出来打印预览页面. 本章使用Lodop插件进行打印设置,实现打印机 ...