题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2925

题意

n个节点,每个节点都有完全相同的n项服务。

每次可以选择一个节点,破坏该节点和相邻节点的某项服务。

问最多能完全破坏多少服务?

思路

如刘书,

直接枚举状态的子集

注意元素个数为k的集合有C^k_n个子集,那么枚举的时间复杂度为sum{c^k_n * 2^k} = 3^n,当n=16时,3^n=4e7,可以承受。

注意枚举子集可以通过substa = (substa - 1)&sta来做,子集的补集则为substa ^ sta。

感想

1. 一开始觉得枚举时间是2^2n,觉得不行,还是缺乏细致的计算

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;
const int MAXN = ;
const int MAXSTA = << ;
int edges[MAXN][MAXN];
int edgeCnt[MAXN];
int vis[MAXN];
int vis2[MAXSTA];
int dp[MAXSTA]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int n;
for (int ti = ; scanf("%d", &n) == && n; ti++) {
for (int i = ; i < n; i++) {
scanf("%d", edgeCnt + i);
for (int j = ; j < edgeCnt[i]; j++) {
scanf("%d", edges[i] + j);
}
}
int maxsta = ( << n) - ;
for (int sta = ; sta <= maxsta; sta++) {
memset(vis, , sizeof vis);
for (int i = ; i < n; i++) {
if (sta & ( << i)) {
vis[i] = true;
for (int j = ; j < edgeCnt[i]; j++) {
vis[edges[i][j]] = true;
}
}
}
bool fl = true;
for (int i = ; i < n; i++) {
if (!vis[i]) {
fl = false;
}
}
if (fl) {
dp[sta] = ;
}
else {
dp[sta] = ;
} }
for (int sta = ; sta <= maxsta; sta++) {
for (int subSta = sta; subSta != ; subSta = (subSta - ) & sta) {
dp[sta] = max(dp[sta], dp[sta ^ subSta] + dp[subSta]);
} }
printf("Case %d: %d\n", ti, dp[maxsta]);
} return ;
}

UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2的更多相关文章

  1. UVA 11825 Hackers’ Crackdown 状压DP枚举子集势

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  2. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  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 (状压DP)

    题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务. 析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的 ...

  6. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  7. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

  8. [Luogu P3959] 宝藏 (状压DP+枚举子集)

    题面 传送门:https://www.luogu.org/problemnew/show/P3959 Solution 这道题的是一道很巧妙的状压DP题. 首先,看到数据范围,应该状压DP没错了. 根 ...

  9. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

随机推荐

  1. java创建线程的方法

    1.1      创建线程 1.1.1     无返回值的线程创建 package com.first; public class ThreadTest { public static void ma ...

  2. Racadm设置idrac

    参考文档  idrac7-8-lifecycle-controller-v2.40.40.40_Reference Guide_en-us 0.下文中账户名密码均省略-r <RAC IP add ...

  3. 基于 Spring Cloud 完整的微服务架构实战

    本项目是一个基于 Spring Boot.Spring Cloud.Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目. @作者:Sheldon地址:ht ...

  4. Python 编程快速上手 第十八章 用 GUI 自动化控制键盘和鼠标

    前言 这一章节讲述了如何实现 GUI 自动化,首先讲了一些处理异常状况的方法,然后是关于 GUI 自动化的内容,主要有三个部分: 控制鼠标 图像识别 控制键盘 下面引用一段话: 请将 GUI 自动化看 ...

  5. Juniper基础配置

    root> show configuration | display set      配置按set行显示,查看的配置为未commit的配置(commit check)root# set sys ...

  6. linux权限管理之文件属性

    文件属性 chattr ======================================================== 文件权限管理之: 文件属性注:设置文件属性(权限),针对所有用 ...

  7. 11月28日 记录一个错误❌,看ruby on rails --active support core extensions--present? && presence && duplicable?

    ❌错误 1. @job.resume.count: 提示❌   undefined method `resume' ✅: @job.resumes.count  //解释:调出某一个job的所有简历, ...

  8. Django 的 orm 查询

    一.模型关系表 1. 一对一 Author-AuthorDetail 关联字段可以在任意表下,但必须唯一约束.(unique约束) ad_id(unique约束) ad = models.oneToO ...

  9. Python 2.7.x 使用Requests发起https请求时报Warning的问题

    warning :如下 /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:852: ...

  10. 创建springboot的聚合工程(二)

    前篇已经成功创建了springboot的聚合工程并成功访问,下面就要开始子工程木块之间的调用: springboot项目的特点,一个工程下面的类必须要放在启动类下面的子目录下面,否则,启动的时候会报错 ...