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 ...
随机推荐
- C#数据类型 值传递和引用传递
/// <summary> /// 电脑类 /// </summary> public class Computer { public string Type { get; s ...
- WebStorm快捷键(Mac版)
编辑 Command+alt+T 用 (if..else, try..catch, for, etc.)包住 Command+/ 注释/取消注释的行注释 Command+alt+/ 注释/取消注释与块 ...
- Web前端体系的脉络结构
Web前端技术由 html.css 和 javascript 三大部分构成,是一个庞大而复杂的技术体系,其复杂程度不低于任何一门后端语言.而我们在学习它的时候往往是先从某一个点切入,然后不断地接触和学 ...
- django之母版的继承
模板继承示例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 系统有问题基本出在数据库上,web层无状态
系统有问题基本出在数据库上,web层无状态.
- POJ 1651 Multiplication Puzzle (区间DP,经典)
题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...
- 使用代码获得Netweaver里某个software component和C4C的版本
有同事问如何通过代码的方式获得Netweaver里某个Software component的版本信息,以及Cloud for Customer(C4C)的版本信息. Netweaver 点了Detai ...
- 感觉单链表是实现BCL ICollection 的最佳方式,所有操作都能以最小的时间复杂度完成
public interface ICollection<T> : IEnumerable<T>, IEnumerable { int Count { get; }// ...
- UVA 10905 Children's Game (贪心)
贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止. #include<bits/stdc++.h> using namespace std; ; stri ...
- [uva816]AbbottsRevenge Abbott的复仇(经典迷宫BFS)
这题思路就普通的BFS加上一个维度朝向,主要是要注意输入,输出,以及细节的处理 #include<cstdio> #include<cstring> #include<q ...