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个物品的特征都互不相同), 最小需要多少次询问? 析:我们假设心中想的那个物 ...
随机推荐
- paxos算法之粗浅理解
paxos出身 paxos出身名门,它爹是没多久前获得图灵奖的在分布式领域大名鼎鼎的LeslieLamport. paxos为何而生 那么Lamport他老人家为什么要搞这个东东呢,不是吃饱了撑的,而 ...
- python发送post请求上传文件,无法解析上传的文件
前言 近日,在做接口测试时遇到一个奇葩的问题. 使用post请求直接通过接口上传文件,无法识别文件. 遇到的问题 以下是抓包得到的信息: 以上请求是通过Postman直接发送请求的. 在这里可以看到消 ...
- JAVA RMI远程方法调用简单实例(转载)
来源:http://www.cnblogs.com/leslies2/archive/2011/05/20/2051844.html RMI的概念 RMI(Remote Method Invocati ...
- Linux 中权限的再讨论( 下 )
前言 上篇随笔讲述了Linux中权限的大致实现机制以及目录权限的相关规则.本文将讲解Linux中的三种特殊权限:SUID,SGID,Sticky权限.看完这两篇文章,你一定会对Linux的权限有个更深 ...
- 【转】IDA Pro7.0使用技巧总结
俗话说,工欲善其事,必先利其器,在二进制安全的学习中,使用工具尤为重要,而IDA又是玩二进制的神器,以前在使用IDA的时候,只是用几个比较常用的功能,对于IDA的其他功能没有去研究,于是本着学习的精神 ...
- Problem binding to [bigdata-server-01:9000] java.net.BindException: Cannot assign requested address;
If the port is "0", then the OS is looking for any free port -so the port-in-use and port- ...
- smod包含具体的增强(具体实施对象) / CMOD 包含一组smod编写的增强
从标题来看,CMOD 是树木,smod 是树枝. 1.1 SMOD包含具体的增强,而CMOD是包含一组SMOD编写的增强. 1.2 User exits (Function module exits) ...
- appium(8)-locator strategies
locator strategies Finding and interacting with elements Appium supports a subset of the WebDriver l ...
- POJ2478 Farey Sequence —— 欧拉函数
题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K To ...
- UVA11892 ENimEN —— 博弈
题目链接:https://vjudge.net/problem/UVA-11892 题意: 两人玩游戏,有n堆石子,每堆有ai块石子,两人轮流取,要求一次只能选择一堆石子取任意块.最后取完的获胜. 题 ...