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中服务,每台服务器还和若干台其他服 ...
随机推荐
- 详解JAVA字符串类型switch的底层原理
基础 我们现在使用的Java的版本,基本上是都支持String类型的.当然除了String类型,还有int.char.byte.short.enum等等也都是支持的.然而在其底部实现中,还是基于 整型 ...
- try(){}自动释放资源,AutoCloseable
我们在使用资源的时候,必须关闭资源,比如使用jdbc连接或者inputStream的时候,必须在finally中将资源关闭.然而有的时候我们会忘记关闭资源.那么有没有更好的方法呢? SqlSessio ...
- CCF 模拟试题——出现次数最多的数 官方答案解析及自己写的正确答案
前几天知道的CCF计算机职业资格认证考试,觉得好像比软考含金量高一些,就去了解了一下,做了模拟试题中的 “出现次数最多的数” 这道题,我的算法和官方答案算法不同,个人觉得觉得官方的好一点,没那么繁琐, ...
- 作为一名Android开发者,你有过迷茫吗?
前言 经常听新进的小白问道,Android是不是饱和了?想写一篇关于Android开发者忧虑的文章很久了,今天才提起勇气写.最近不管是在微信.QQ群,还是在各大博客网站,都随处听得到Android开发 ...
- Spring Boot 利用 nginx 实现生产环境的伪热更新
当我们在服务器部署Java程序,特别是使用了 Spring Boot 生成单一 Jar 文件部署的时候,单一文件为我们开发单来的极大的便利性,保障程序的完整性.但同时对我们修改程序中的任何一处都带来重 ...
- json-lib包引入失败的解决方法
要想使用json-lib的依赖必须加入<classifier>jdk15</classifier> 这一行,否则就导入依赖时就会失败报错,下载不下来jar包,因为json-li ...
- Vue学习之vue中的v-if,v-show,v-for
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [Advanced Python] 13 - "Decorator": syntactic sugar
单独一章复习:Python 函数装饰器,廖雪峰讲装饰器 基本概念 函数作为变量 从函数中返回函数 子函数写在外面貌似也可以,可这样就少了“封装性”. def greet(): return " ...
- 【译】Kubernetes监控实践(2):可行监控方案之Prometheus和Sensu
本文介绍两个可行的K8s监控方案:Prometheus和Sensu.两个方案都能全面提供系统级的监控数据,帮助开发人员跟踪K8s关键组件的性能.定位故障.接收预警. 拓展阅读:Kubernetes监控 ...
- Chrome 调试AJAX请求返回的JS脚本
有时候会使用AJAX请求加载局部的Html页面,这个时候如果想调试局部页面中的js就比较麻烦,现在暂时发现了两种方法.第一种是在js代码中想要断点的地方加debugger,这样代码执行到此处会进入断点 ...