题意:

给出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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. SCU 4439 Vertex Cover(二分图最小覆盖点)题解

    题意:每一条边至少有一个端点要涂颜色,问最少涂几个点 思路:最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联,显然是道裸最小顶点覆盖题: 参考:二分图 代码: #include<iost ...

  4. 第十五届四川省省赛 SCU - 4439 Vertex Cover

    给你一个一般图 保证每条边的一端下标不大于30 问最小覆盖集的大小为多少 爆搜:枚举前30个点是否在覆盖集内 剪枝1:如果不在的话 那么他所连的下标大于30的点都必须选 剪纸2:最优解剪枝 #incl ...

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

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

  6. 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 ...

  7. PAT1134:Vertex Cover

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. Appium-两个小报错

    (1)     执行脚本appium报错:> info: [debug] Emulator not running appium设置中取消勾选launch avd解决 (2)执行脚本python ...

  2. storm配置文件

  3. EXPLAIN执行计划中要重点关注哪些要素(叶金荣)

    原文:http://mp.weixin.qq.com/s/CDKN_nPcIjzA_U5-xwAE5w 导读 EXPLAIN的结果中,有哪些关键信息值得注意呢? MySQL的EXPLAIN当然和ORA ...

  4. SpringMVC(三):参数绑定、输入输出转换

    一.参数解析绑定 1. 自定义绑定:不绑定某些项 @InitBinder private void initBinder(WebDataBinder dataBinder) { dataBinder. ...

  5. 【SQL】SQL Between用法

  6. 微信小程序添加悬浮在线客服会话按钮

    微信为小程序提供客服消息能力,小程序用户可以方便快捷地与小程序服务提供方进行沟通,并且已经做成了组件的形式,直接就可以调用.客服会话按钮,用于在页面上显示一个客服会话按钮,用户点击该按钮后会进入客服会 ...

  7. hdu1240/poj2225 BFS广搜的再理解

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/guodongxiaren/article/details/37756347 原题地址 pid=124 ...

  8. MySQL的nnodb引擎表数据分区存储

    Symlinks are fully supported only for MyISAM tables. 对应Innodb引擎数据文件放到其他目录 mysql> SHOW VARIABLES L ...

  9. 启动Jmeter4.0 后弹出命令窗口提示信息是什么意思?

    启动Jmeter4.0 后弹出命令窗口提示信息: =========================================================================== ...

  10. DAX/PowerBI系列 - 参数表(Parameter Table) - 大客户分析(Top N)

    DAX/PowerBI系列 - 参数表(Parameter Table) - 大客户分析(Top N) 难度: ★☆☆☆☆(1星) 适用范围: ★★★☆☆(3星) 概况:此文为DAX/PowerBI系 ...