algorithm - 找到从 s 到每个 v 的最短路径,并限制长度

标签 algorithm graph computer-science

Let G(V,E) a directed graph with weights w:E->R. Let's assume |V| is dividable by 10. Let s in V. Describe an algorithm to find a shortest path from s to every v such that it contains exactly |V|/10 edges.

所以一开始我考虑过使用动态规划,但我最终得到了 O(|V|^3) 的复杂度,这显然不是这个练习的最佳选择。

我们不能使用 Bellman-Ford(据我所知),因为可能存在负循环。

这个问题的最佳算法是什么?

谢谢

编辑

我忘了提一个关键信息;路径可以不简单。即我们可能会在路径中重复边。

最佳答案

您可以在图表上执行限制为 |V|/10 的深度限制搜索。它将帮助您找到成本最低的路径。

limit = v_size / 10
best[v_size] initialize to MAX_INT

depth_limited(node, length, cost)
    if length == limit
        if cost < best[node]
            best[node] = cost
        return
    for each u connected to node
        depth_limited(u, length+1, cost + w[node][u])

depth_limited(start_node, 0, 0)

关于algorithm - 找到从 s 到每个 v 的最短路径,并限制长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39531556/

相关文章:

algorithm - 帮助 Donalds B. Johnson 的算法,我无法理解伪代码(第二部分)

php - 如何使用 php、graph API 通过 id 删除 facebook 中的帖子

java - 难以理解计数和平均值

algorithm - 哈密​​顿循环的归约算法

algorithm - 推流重新标记算法

java - 我如何知道算法是在 O(n) 时间内运行还是在 O(nlogn) 内运行?

algorithm - 如何知道 MPEG DASH 中的直播何时结束?

algorithm - 两组N个人围着一圈能找到对方吗?

javascript - 变量声明是否与变量的绑定(bind)相同?

algorithm - 如何有效地为一场 8 球比赛筹备台球?