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 ...
随机推荐
- 使用jquery.uploadify上传文件
今天在网上找了一天,想要找到一个比较全的使用案例,结果发现基本上全是一个版本的... 我的问题主要是上传完成后,还需要将路径获取到,然后保存到数据库. 查了一下资料发现有这么一个参数onComplet ...
- php 数值类型
一.整形 1. 常见的整形 echo 1234; // 十进制数 echo -123; // 负数 echo 0123; // 八进制数 (等于十进制 83) echo 0x1A; // 十六进制数 ...
- 分布式文档系统_document查询内部原理
1.客户端发送请求到任意一个node,成为coordinate node2.coordinate node对document进行路由,将请求转发到对应的node,此时会使用round-robin随机轮 ...
- (4.7)mysql备份还原——深入解析二进制日志(3)binlog的三种日志记录模式详解
关键词:binlog模式,binlog,二进制日志,binlog日志 目录概述 0.binlog概述 查看binlog日志参数设置: show variables like '%log_bin%'; ...
- cxGrid常用属性设置
OptionsView部分 是否使用表头分组:cxGrid1DBTableView1.OptionsView.GroupByBox 单元格高度自适应:cxGrid1DBTableView1.Optio ...
- 自动化工具之三:pywinauto
Python自动化工具:pywinauto 一.pywinauto的安装 (1)安装命令 pip install -U pywinauto/pip3 install -U pywinauto (2)验 ...
- PE破解win2008登录密码
1.使用PE系统启动计算机. 2.使用cmd命令行程序. 3.备份一下magnify.exe(windows 放大镜程序). copy C:\WINDOWS\system32\magnify.exe ...
- javaScript 数组迭代方法
map 方法 解释:map即映射,返回对每项操作后组成的新数组 let arr=[1,2,3,4,5,6,7,8]; let newArr=arr.map((item)=>{ if(item&g ...
- 算法 -- 求最长公共字符串&PHP
https://blog.csdn.net/hongyuancao/article/details/83308093 本文是利用PHP,求最长公共字符串.思路:利用动态规划和矩阵的思想. 动态规划:就 ...
- Exception in thread “main” java.sql.SQLException: No suitable driver
问题背景:通过Spark SQL的jdbc去读取Oracle数据做测试,在本地的idea中没有报任务错误.但是打包到集群的时候报: Exception in thread “main” java.sq ...