Hackers' Crackdown UVA - 11825
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的更多相关文章
- Hackers' Crackdown UVA - 11825 (状压dp)
给出n个电脑,每个电脑连着n个服务,然后每个电脑都连着m个邻电脑,如果当前的电脑某个服务被断开了,相邻的电脑的服务也会被断开,每个电脑都只能操作一次,问你最多可以让多少种服务被断开.一种服务被断开的条 ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- UVA 11825 Hackers' Crackdown
题目大意就是有一个图,破坏一个点同时可以破坏掉相邻点.每个点可以破坏一次,问可以完整破坏几次,点数=16. 看到16就想到状压什么的. 尝试设状态:用f[i]表示选的情况是i(一个二进制串),至少可以 ...
- [Uva 11825] Hackers’ Crackdown
Hackers’ Crackdown Input: Standard Input Output: Standard Output Miracle Corporations has a numbe ...
- UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)
Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
- UVA 11825 Hackers’ Crackdown 状压DP枚举子集势
Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...
- 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 ...
- UVa 11825 (状压DP) Hackers' Crackdown
这是我做状压DP的第一道题,状压里面都是用位运算来完成的,只要耐下心来弄明白每次位运算的含义,还是容易理解的. 题意: 有编号为0~n-1的n台服务器,每台都运行着n中服务,每台服务器还和若干台其他服 ...
随机推荐
- 【Offer】[37] 【序列化二叉树】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 请实现两个函数,分别用来序列化和反序列化二叉树. 二叉树的序列化是指:把一棵二叉树按照某种遍历方式的结果以某种格式保存为字符串,从而使得 ...
- 运行sudo apt-get install nginx时报错有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?解决
运行sudo apt-get install nginx时报错有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?解决办法 第一步:运行s ...
- Android开发教程:开发框架基本原理
1.提供应用程序框架(Framework) 开发者可以遵照这些框架搭建应用程序读者可以结合J2SE平台的Applet框架或J2ME平台的移动信息设备套件框架来理解Android平台的应用程序框架. 每 ...
- Solve Hibernate Lazy-Init issue with hibernate.enable_lazy_load_no_trans
I have been suffering from infamous hibernate exception org.hibernate.LazyInitializationException: c ...
- 用vetr.x写一个HTTP接口适配器, 对接各种形式接口
用vetr.x写一个HTTP接口适配器, 对接各种形式接口 项目地址:https://github.com/hjx601496320/transmit 业务说明 在日常开发工作中,我们经常会遇到要和各 ...
- The 10 Most Important Linux Commands/10个最经常使用的命令行
1. ls 命令:to show all of the major directiories filed under a given file system. for example: ls /app ...
- uboot学习之uboot-spl的程序流程分析
uboot-spl的程序流程主要包含下面的几个函数: _start->reset->save_boot_params->cpu_init_crit->lowlevel_init ...
- JavaScript之操作符
计算机被发明的初衷仅仅是为了快速实现一些数学计算,然而经过多年发展,计算机已经不单单能实现快速计算这么简单的工作了,现代计算机不仅能够进行数值的计算,还能进行逻辑计算,还具备存储记忆功能,是能够按照程 ...
- Python学习-迭代器、生成器
一.迭代器 1. 可迭代对象 我们知道字符串.列表.元组.字典.集合都可以使用for语句进行循环遍历,然后输出每一个元素,这些都是可迭代对象. 检查对象是否是可迭代对象可以用两种方式去判断: (1)使 ...
- Anaconda基本认识
Anaconda Distribution是执行Python数据科学和机器学习最简单的方法. 它包括250多种流行的数据科学软件包,以及适用于Windows,Linux和MacOS的conda软件包和 ...