【问题标题】:Dynamic Programming: Vertex Cover of simple graphs动态规划:简单图的顶点覆盖
【发布时间】:2015-02-17 16:31:09
【问题描述】:

我正在寻找一种有效的算法来找到两个特定图的最小成本顶点覆盖,其中顶点具有不同的成本。

第一个图是一个排序链表,其中 V={1...n} 和 E={{1,2},{2,3},{3,4}... {n-1,n}}

第二张图是一个简单的循环。与上面基本相同,但 {n,1} 也是一条边。

我已经找到了一种递归方法,通过简单地检查每个节点是否应该在顶点覆盖中。

VC(Graph G(V,E)):
  if(|V|=0) return 0
  u=first node of V
  v=second node of V
  return min(VC(Graph.remove(u)+cost(u),   //Case where the first node is in VC
             VC(Graph.remove(v,u))+cost(v)) //Case where second node is in VC

然而这确实是低效的,有没有办法使用动态编程来改进这一点?

【问题讨论】:

  • 你可以使用那些特定图表的结构吗?否则你会有麻烦的..
  • 是的!明确地。他们只需要为这些图表工作。

标签: algorithm graph dynamic-programming


【解决方案1】:
  1. 对于链,动态规划解决方案非常简单。状态为(number of vertices processed, is the last vertex taken)。状态的值是覆盖这部分图的最小成本。

  2. 对于一个循环,我们可以使用以下观察:第一个或第二个顶点在封面中。因此,我们可以通过删除第一个或第二个顶点并选择最佳答案来将其简化为 1) 问题。

这两种解决方案都具有线性时间复杂度。

第 1 部分的一些伪代码:

f(1, false) = 0 // do not take the first vertex
f(1, true) = cost(1) // take it
for v <- 2 ... n:
    f(v, false) = f(v - 1, true) // do not take the current vertex
    f(v, true) = min(f(v - 1, true), f(v - 1, false)) + cost(v) // take it
print(min(f(n, false), f(n, true)))

【讨论】:

  • 这真的很有趣。您能在第 1 部分中开发更多内容吗?
  • 甜蜜!这太棒了!
猜你喜欢
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-19
相关资源
最近更新 更多