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. Python大佬告诉你:使用Python处理yaml格式的数据简单到爆

    一.思考❓❔ 1.什么是yaml? 不是标记语言 对用户极其友好 数据序列化标准 跨语言 所有编程语言都支持 跨平台 所有平台都支持 Windows.linux.Mac 格式简单 比json小姐姐穿得 ...

  2. 巨杉Tech | Hbase迁移至SequoiaDB 实战

    背景 在传统银行 IT 架构中,联机交易与统计分析系统往往采用不同的技术与物理设备,通过定期执行的 ETL 将联机交易数据向分析系统中迁移.而作为数据服务资源池,同一份数据可能被不同类型的微服务共享访 ...

  3. 二分练习题2 查找大于等于x的最小元素 题解

    题目描述 现在告诉你一个长度为 \(n\) 的有序数组 \(a_1, a_2, ..., a_n\) ,以及 \(q\) 次询问,每次询问会给你一个数 \(x\) ,对于每次询问,你需要输出数组 \( ...

  4. Centos7上安装jdk8

    CentOS7 下安装jdk8环境 1 检查服务器环境 首先,我们需要检查一下服务器是否安装过java环境,可以使用如下命令: java -version 如果已经安装有java环境,会出现类似于以下 ...

  5. CSS——边框设置

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. charles 启用/禁用断点

    本文参考:charles 启用/禁用断点 1.3. enable/disable breakpoints 和 2.3 breakpoints settings 断点设置是常用的了,没啥好说的了,可以设 ...

  7. 工厂/Builder,桥接/策略

    1.工厂 vs 抽象工厂 工厂方法模式: 用来加工.生产对象的类.比如说我想要一个汽车类,但是我总不能现场给你造个车出来对吧?于是我找到工厂类,然后工厂帮我把发动机型号选好,轮胎装好,油漆喷好,然后把 ...

  8. android studio连接雷电模拟器 【AS 模拟器】

    ⭐ 我的网站: www.mengyingjie.com ⭐ Android studio 怎么连接安卓模拟器呢,跟着下面的步骤即可 (以雷电模拟器为例,其他模拟器类似) 一.下载模拟器 下载安装完雷电 ...

  9. EditPlus 全系列 注册码

    EditPlus4注册码 注册名:host1991 序列号:14F50-CD5C8-E13DA-51100-BAFE6  注册名:360xw 注册码:93A52-85B80-A3308-BF130-4 ...

  10. Docker下实战zabbix三部曲之一:极速体验

    对于想学习和实践zabbix的读者来说,在真实环境搭建一套zabbix系统是件费时费力的事情,本文内容就是用docker来缩减搭建时间,目标是让读者们尽快投入zabbix系统的体验和实践: 环境信息 ...