题意:

给出一个\(n\)个点\(m\)条边的无向图,现在要给若干个点染色,使得每条边都至少邻接一个被染色的顶点.问至少要给多少各点染色才能满足条件.

分析:

注意到题目中有一个很特殊的条件:

对于图中任意一条边\(u,v\),有\(min \{ u,v \} \leq 30\)

所以最坏的情况下,最多染30个点就可以满足条件.

所以用bitset维护一下当前被染色的点的情况即可.

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std; const int maxn = 30; bitset<500> g[maxn];
int n, m, tot, ans; void dfs(int d, bitset<500> t) {
int cnt = t.count();
if(cnt >= ans) return ;
if(d == tot) {
ans = min(ans, cnt);
return ;
} if(t[d]) dfs(d + 1, t);
else {
t[d] = 1;
dfs(d + 1, t);
t[d] = 0;
dfs(d + 1, t | g[d]);
}
} int main()
{
while(scanf("%d%d", &n, &m) == 2) {
tot = min(30, n);
for(int i = 0; i < tot; i++) g[i].reset(); while(m--) {
int x, y; scanf("%d%d", &x, &y);
x--; y--;
if(x > y) swap(x, y);
g[x][y] = 1;
if(y < tot) g[y][x] = 1;
} bitset<500> t;
t.reset();
ans = tot;
dfs(0, t);
printf("%d\n", ans);
} return 0;
}

2015四川省赛 D Vertex Cover 搜索的更多相关文章

  1. 2015 四川省赛 C Censor(哈希 | KMP)

    模式串为子串 KMP /* @author : victor */ #include <bits/stdc++.h> using namespace std; typedef long l ...

  2. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  3. URAL 2038 Minimum Vertex Cover

    2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...

  4. PAT1134:Vertex Cover

    1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...

  5. A1134. Vertex Cover

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  6. PAT A1134 Vertex Cover (25 分)——图遍历

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  7. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  8. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  9. SCU - 4439 Vertex Cover (图的最小点覆盖集)

    Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a ...

随机推荐

  1. jar包生成exe可执行程序

    1.生成工具EXE4J下载链接:https://www.ej-technologies.com/download/exe4j/files 2.安装.使用:https://blog.csdn.net/h ...

  2. HBase数据模型(1)

    HBase数据模型(1) HBase数据模型(2) 1.0 HBase的特性 Table HBase以表(Table)的方式组织数据,数据存储在表中. Row/Column 行(Row)和列(Colu ...

  3. Android Doze模式源码分析

    科技的仿生学无处不在,给予我们启发.为了延长电池是使用寿命,google从蛇的冬眠中得到体会,那就是在某种情况下也让手机进入类冬眠的情况,从而引入了今天的主题,Doze模式,Doze中文是打盹儿,打盹 ...

  4. APP自动化测试

    CTS工具,主要是基于Androidinstrumentation和JUnit测试原理推单元测试用例: Monkey用来对UI进行压力测试,伪随机的模拟用户的按键输入,触摸屏输入,手势输入等: ASE ...

  5. 关于JavaScript的变量和函数提升

    第一种理解方式:let和const不能被使用,直到他们被声明 对于var定义的变量,解析器会提升其到作用域顶部. // Outputs: undefined console.log(x); var x ...

  6. Unity runtime性能分析器

    一. Profiler: 1. CPU Usage A. WaitForTargetFPS: Vsync(垂直同步)功能所,即显示当前帧的CPU等待时间 B. Overhead: Profiler总体 ...

  7. J.U.C知识点梳理

    java.util.concurrent : 提供了并发编程的解决方案 1.CAS 是java.util.concurrent.atomic包的基础 2.AQS是java.util.concurren ...

  8. maven,gradle本地缓存位置

    gradle: 配置系统环境变量GRADLE_USER_HOME即可,值为缓存位置. maven: 修改settings文件:maven的home路径下的conf文件夹下的settings.xml 对 ...

  9. 01_6_SERVLET如何从上一个页面取得参数

    01_6_SERVLET如何从上一个页面取得参数 1. sevlet实现 public void doGet(HttpServletRequest request, HttpServletRespon ...

  10. DD命令做备份和恢复

    正确的备份方法是先挂载移动硬盘分区:mount /dev/sdb5 /mnt 然后再备份:dd if=/dev/sda of=/mnt/backup_sda.img 恢复时同样要先挂载,再恢复:mou ...