UVa 11825 Hackers' Crackdown (状压DP)
题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务。
析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的的 u 是全集。我们可以用状压DP来解决,先处理输入,然后再处理每个子集,
dp[s] 表示状态为 s 时,最多能终止多少服务,dp[s] = max{ dp[s^s0] +1 }。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = (1<<16) + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp[maxn];
int a[20], s[maxn]; int main(){
int kase = 0;
while(scanf("%d", &n) == 1 && n){
for(int i = 0; i < n; ++i){
scanf("%d", &m);
a[i] = 1 << i;
int x;
while(m--){
scanf("%d", &x);
a[i] |= 1 << x;
}
}
for(int i = 0; i < (1<<n); ++i){
s[i] = 0;
for(int j = 0; j < n; ++j)
if(i & (1<<j)) s[i] |= a[j];
}
int all = (1<<n) - 1;
dp[0] = 0;
for(int i = 1; i < (1<<n); ++i){
dp[i] = 0;
for(int j = i; j; j = (j-1)&i)
if(s[j] == all) dp[i] = max(dp[i], dp[i^j]+1);
}
printf("Case %d: %d\n", ++kase, dp[all]);
}
return 0;
}
UVa 11825 Hackers' Crackdown (状压DP)的更多相关文章
- UVA 11825 Hackers’ Crackdown 状压DP枚举子集势
Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...
- [UVA11825]Hackers' Crackdown(状压dp)
题解降智警告 吐槽降智警告 思路降智警告 代码降智警告 题目传送门 洛谷 果然水题做多了连半道难点的都能给咱干蒙... 水题做多了降智 --鲁迅 题目大意:见传送门 心路历程见末尾 正解(大概): ...
- UVA11825 黑客的攻击 Hackers' Crackdown 状压DP,二进制,子集枚举
题目链接Click Here [题目描述] 假如你是一个黑客,侵入了一个有着\(n\)台计算机(编号为\(1.2.3....n\))的网络.一共有\(n\)种服务,每台计算机都运行着所有服务.对于每台 ...
- [Uva 11825] Hackers’ Crackdown
Hackers’ Crackdown Input: Standard Input Output: Standard Output Miracle Corporations has a numbe ...
- UVa 1204 Fun Game (状压DP)
题意:有一些小孩(至少两个)围成一圈,有 n 轮游戏,每一轮从某个小孩开始往左或者往右伟手帕,拿到手帕写上自己的性别(B,G),然后以后相同方向给下一个. 然后在某个小孩结束,给出 n 轮手帕上的序列 ...
- UVA 11825 Hackers' Crackdown
题目大意就是有一个图,破坏一个点同时可以破坏掉相邻点.每个点可以破坏一次,问可以完整破坏几次,点数=16. 看到16就想到状压什么的. 尝试设状态:用f[i]表示选的情况是i(一个二进制串),至少可以 ...
- UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)
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 1252 Twenty Questions (状压DP+记忆化搜索)
题意:有n件物品,每件物品有m个特征,可以对特征进行询问,询问的结果是得知某个物体是否含有该特征,要把所有的物品区分出来(n个物品的特征都互不相同), 最小需要多少次询问? 析:我们假设心中想的那个物 ...
随机推荐
- 逆向project实战--Afkayas.1
0x00 序言 去年玩了几个月的渗透測试,当初认为非常高端的样子.如今看来只是都是些小把戏,于是開始折腾逆向project. 学习过程中參考的是<逆向project核心原理>这本书.讲的非 ...
- 怎样退出App之前唤醒还有一个App?
郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 SDK并没 ...
- mongodb查看连接数、同步时间、oplog及修改表名的操作
1) mongodb查看连接数: db.serverStatus().connections; 2) mongodb查看同步时间: db.printSlaveReplicationInfo(); % ...
- CIDR(无类域间路由)(转载)
来源:百度百科 CIDR(无类型域间选路,Classless Inter-Domain Routing)是一个在Internet上创建附加地址的方法,这些地址提供给服务提供商(ISP),再由ISP分配 ...
- SAM4E单片机之旅——8、UART初步
通信还是比让LED灯闪烁实用得多的. 这次试试使用UART,实现开发版和PC间的通信.功能比较简单,就是把PC发向开发版的内容发送回去.这次主要介绍一下UART的配置,至于通信,则使用较为简单的不断查 ...
- Storage Types and Storage Policies
https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html Introduc ...
- spring IOC(转)
原文 http://stamen.iteye.com/blog/1489223 引述:IoC(控制反转:Inverse of Control)是Spring容器的内核,AOP.声明式事务等功能在此基础 ...
- 操作Zookeeper
可以通过图形化界面进行操作使用的工具是 zookeeper-dev-ZooInspector.jar 连接到我的zk之后: 1.Java操作zk 依赖: <dependency> < ...
- BluetoothLE-Multi-Library
github地址:https://github.com/qindachang/BluetoothLE-Multi-Library BluetoothLE-Multi-Library 一个能够连接多台蓝 ...
- HDU-2255(KM算法)
HDU-2255 题目意思转化之后就是,给你一个二分图(也称 二部图) ,要求选择一些边让左边的点都对应左边的某一个点!该问题也叫做二分图最大匹配.所以可以用KM算法来做这道题.KM前提你要理解匈牙利 ...