scu 4439 Vertex Cover
题意:
给出n个点,m条边,将若干个点染色,使得每个边至少有一点染色,问至少染多少个点。
思路:
如果是二分图,那就是最小点覆盖,但是这是一般图。
一般图的最小覆盖是npc问题,但是这题有一个条件比较特殊,就是输入的每条边都保证了至少有一个点小于等于30,所以至多覆盖30个点就可以了。
那么就可以用搜索解决,对于一个点,要么覆盖,要么不覆盖。
如果这个点被覆盖了,就直接往下搜;
如果没有被覆盖,那么就要么覆盖这个点,直接往下搜;要么不覆盖这个点,但把这个点相邻的点全部覆盖,再往下搜。
得剪枝,可行性剪枝和最优性剪枝。
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
const int N = ;
int vis[N];
vector<int> g[N];
int tot;
int ans;
void dfs(int cu,int sum)
{
if (sum > ans) return;
if (cu > tot)
{
ans = sum;
return;
}
if (vis[cu]) dfs(cu+,sum);
else
{
vis[cu]++;
dfs(cu+,sum+);
vis[cu]--;
for (auto x : g[cu])
{
if (!vis[x]) sum++;
vis[x]++;
}
dfs(cu+,sum);
for (auto x : g[cu])
{
vis[x]--;
if (!vis[x]) sum--;
}
}
}
int main()
{
int n,m;
while (scanf("%d%d",&n,&m) != EOF)
{
tot = ;
ans = ;
memset(vis,,sizeof(vis));
for (int i = ;i <= n;i++) g[i].clear();
for (int i = ;i < m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
tot = min(,n);
ans = tot;
dfs(,);
printf("%d\n",ans);
}
return ;
}
scu 4439 Vertex Cover的更多相关文章
- 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 ...
- SCU 4439 Vertex Cover|最小点覆盖
传送门 Vertex Cover frog has a graph with n vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and m edges (v(a1 ...
- SCU 4439 Vertex Cover(二分图最小覆盖点)题解
题意:每一条边至少有一个端点要涂颜色,问最少涂几个点 思路:最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联,显然是道裸最小顶点覆盖题: 参考:二分图 代码: #include<iost ...
- 第十五届四川省省赛 SCU - 4439 Vertex Cover
给你一个一般图 保证每条边的一端下标不大于30 问最小覆盖集的大小为多少 爆搜:枚举前30个点是否在覆盖集内 剪枝1:如果不在的话 那么他所连的下标大于30的点都必须选 剪纸2:最优解剪枝 #incl ...
- 集合覆盖 顶点覆盖: 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 ...
随机推荐
- Python 常用的日期时间命令
今天用到自动添加当前时间,居然把之前的知识忘了,特整理常用的日期时间命令 代码: # 获取当前时间# import time# localtime = time.localtime(time.time ...
- Linux中常用命令
.cd命令 cd 回到跟目录 cd uqihong 进入到uqihong这个文件夹(且cd命令只能一级一级的进入) 2.复制命令 cp -r /usr/local/tomcat ...
- 不看好运维竖井产品模式,优云打造融合化运维PaaS平台
2018年1月13号中国双态运维用户大会上,优云软件总裁刘东海接受了36Kr记者的专访,期间谈到了新时代下的企业运维模式,新兴技术和传统运维的融合以及优云未来的发展方向等问题.以下为访谈实录: 优云软 ...
- 关于linux特殊含义的转义符\033
格式: echo -e "\033[字背景颜色;字体颜色m字符串\033[0m" 例如: echo -e "\033[41;36m something here \033 ...
- 多线程-interrupt(),isInterrupted(),interrupted()(转)
Content 背景 中断 相关方法 阻塞方法 不可中断的阻塞方法 处理不支持中断的线程中断的常用方法 处理InterruptedException 待决中断 实例1 实例2 参考资料 Top 背景 ...
- word2vec参数理解
之前写了对word2vec的一些简单理解,实践过程中需要对其参数有较深的了解: class gensim.models.word2vec.Word2Vec(sentences=None,size=10 ...
- c语言常见编程
//输入一个整数,然后按照原顺序输出相应字符 # import <stdio.h> void main() { void convert (int n); int a; printf (& ...
- OC仿支付宝输入UITextField输入车牌号
效果图,如果使用,出现任何问题请告知,或者下方留言,我好以及改正 .h文件: #import <UIKit/UIKit.h> @interface LicenseKeyBoardView ...
- Spark创建空的DataFrame
前言 本文主要给出Spark创建空的DataFrame的代码示例,这里讲的空的DataFrame主要指有列名(可以自己随意指定),但是没有行的DataFrame,因为自己在开发过程中有这个需求,之前并 ...
- 【LeetCode每天一题】4Sum(4数之和)
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums s ...