2015四川省赛 D Vertex Cover 搜索
题意:
给出一个\(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 搜索的更多相关文章
- 2015 四川省赛 C Censor(哈希 | KMP)
模式串为子串 KMP /* @author : victor */ #include <bits/stdc++.h> using namespace std; typedef long l ...
- 集合覆盖 顶点覆盖: set cover和vertex cover
这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...
- 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 ...
- PAT1134:Vertex Cover
1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...
- 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 ...
- 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 ...
- PAT 甲级 1134 Vertex Cover
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...
- 二分图匹配 + 最小点覆盖 - Vertex Cover
Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...
- 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 ...
随机推荐
- 简述null undefined NaN的异同
1. 类型类型分析: JS中数据类型有5种:string,number,boolean,undefined,object,前四种值类型(基础数据类型),object是引用类型 var a1; //un ...
- I/O操做总结(四))
前面已经把java io的主要操作讲完了 这一节我们来说说关于java io的其他内容 Serializable序列化 实例1:对象的序列化 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- querySelector/querySelectorAll
querySelector获取页面I属性D为test的元素: document.getElementById("test"); //or document.querySelecto ...
- Bootstrap设置按钮禁用
在Bootstrap中,按钮可以使用button标签或者a标签.设置按钮禁用可以通过两种方式,一种是通用CSS样式,一种是用过JS脚本动态设置,下面举例说明! <!DOCTYPE html> ...
- Jquery 日期差函数 修改 对火狐进行兼容
function DateDiff(sDate1, sDate2) { //sDate1和sDate2是yyyy-MM-dd格式 var aDate, oDate1, oDate2, iDays; a ...
- 【虚拟机-远程链接】Azure Windows 虚拟机常见导致无法远程的操作
对Azure虚拟机的一些操作可能会导致无法远程连接,本文罗列了以下导致不能远程连接的场景: 场景1 - 在虚拟机网卡配置中配置IP地址或MAC地址 场景2 - 远程桌面授权过期 场景3 - 误设置“不 ...
- SharePoint 2013 安装配置(3-1)
在第二部分中,我向您展示了如何在Windows Server 2012 R2 for SharePoint 2013上设置Active Directory域服务.现在我们应该能够在Active Dir ...
- Win10自动安装游戏/应用
近日有一些网友反馈Win10会自动安装一些游戏/应用.用户没有打开应用商店并且没有被要求获取批准,系统自动在系统中安装了一些应用. 比如有这样一位网友反馈了该问题,他在自己的系统中使用命令卸载了所有的 ...
- 洛谷 P3387 【模板】缩点
题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只 ...
- 多目标检测分类 RCNN到Mask R-CNN
最近做目标检测需要用到Mask R-CNN,之前研究过CNN,R-CNN:通过论文的阅读以及下边三篇博客大概弄懂了Mask R-CNN神经网络.想要改进还得努力啊... 目标检测的经典网络结构,顺序大 ...