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. Go操作etcd

    etcd是近几年比较火热的一个开源的.分布式的键值对数据存储系统,提供共享配置.服务的注册和发现,本文主要介绍etcd的安装和使用. etcd etcd介绍 etcd是使用Go语言开发的一个开源的.高 ...

  2. ResourceDictionary主题资源替换(二) :通过加载顺序来覆盖之前的主题资源

    之前的ResourceDictionary主题资源替换(一)通过加载顺序来覆盖之前的主题资源,介绍了WPF框架对ResourceDictionary资源的合并规则. 此篇介绍一种在编译期间,实现资源替 ...

  3. Winform中使用FastReport的DesignReport时怎样给通过代码Table添加数据

    场景 FastReport安装包下载.安装.去除使用限制以及工具箱中添加控件: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  4. SpringCloud(四)Hystrix熔断器

    前面已经学习了服务注册与发现组件,负载均衡组件,这样我们的微服务系统已经可以使用了.为了保证其高可用,单个服务通常会集群部署.由于网络原因或者自身的原因,服务并不能保证 100% 可用,如果单个服务出 ...

  5. 秒杀活动是否适合O2O生鲜行业的思考

    一.命题提出背景 公司是O2O生鲜行业,公司的业务部门提出要做秒杀活动.产品负责人听到后说没意义,秒杀不适合O2O生鲜.(产品负责人据说是阿里出来的P8,后来去微信,去永辉带运营.研发,做大佬,再后来 ...

  6. 配置phpmyadmin连接远程 MySQL数据库

      引言:1.phpmyadmin程序所在服务器:192.168.1.1,访问地址为:http://192.168.1.1/phpmyadmin2.MySQL数据库所在服务器:192.168.1.2, ...

  7. 搜索专题题解(FJUT - OJ 17级搜索强化训练)

    题目连接:http://120.78.128.11/Contest.jsp?cid=221#H 题目都比较难,每道题都很经典,我也做的很慢,这篇博文算是个收录.具体题目题解点击下面超链接吧. 一.Br ...

  8. Fliptile(枚举+DFS)

    Problem Description Farmer John knows that an intellectually satisfied cow is a happy cow who will g ...

  9. 阿里云Centos 7安装MongoDB 4.2.0

    背景:最近公司项目需要将后台接口优化到100ms内.因此需要对接口逻辑,数据优化做处理, 正好使用到了Redis缓存,mysql,mongoDB的优化,今天记录一下在阿里云centos上安装mongo ...

  10. 从Hybrid到React-Native: JS在移动端的南征北战史

    注:因为不了解Dart,所以本文不对flutter相关内容进行阐述, 实在抱歉 Hybrid Hybird是一种混合开发应用,可以实现JS和Java代码的互通,单纯使用ios/android原生实现, ...