查找图中没有任何负前缀的最短路径

编程入门 行业动态 更新时间:2024-10-25 11:35:14
本文介绍了查找图中没有任何负前缀的最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在有正负边的有向图中找到从源到目的地的最短路径,以使路径中的任何点之前的边之和为负.如果没有这样的路径,也要报告.

Find the shortest path from source to destination in a directed graph with positive and negative edges, such that at no point in the path the sum of edges coming before it is negative. If no such path exists report that too.

我试图使用改良的Bellman Ford,但找不到正确的解决方案.

I tried to use modified Bellman Ford, but could not find the correct solution.

我想澄清几点:

是,体重循环可能为负数.
  • n是边的数量.
  • 如果问题有解决方案,则假定存在O(n)个长度路径.
  • + 1/-1边缘权重.
  • yes there can be negative weight cycles.
  • n is the number of edges.
  • Assume that a O(n) length path exists if the problem has a solution.
  • +1/-1 edge weights.
  • 推荐答案

    诚然,这不是一个建设性的答案,但是在评论中发布太久了……

    Admittedly this isn't a constructive answer, however it's too long to post in a comment...

    在我看来,这个问题包含二进制和离散背包问题,因此,最坏情况下的运行时间充其量是伪多项式.考虑一个按如下所示连接和加权的图:

    It seems to me that this problem contains the binary as well as discrete knapsack problems, so its worst-case-running-time is at best pseudo-polynomial. Consider a graph that is connected and weighted as follows:

    然后,等效的二进制背包问题正在尝试从集合{ a 0 ,..., a 中选择权重 n }最大化Σ a i ,其中Σ a i < X .

    Then the equivalent binary knapsack problem is trying to choose weights from the set {a0, ..., an} that maximizes Σ ai where Σ ai < X.

    作为附带说明,如果我们引入加权循环,则可以轻松构造无界背包问题.

    As a side note, if we introduce weighted loops it's easy to construct the unbounded knapsack problem instead.

    因此,您可能选择的任何实用算法的运行时间取决于您认为平均"情况的时间.对我未曾考虑或无法解决的问题是否有限制?您似乎很确定这是一个O( n 3 )问题.(尽管在这种情况下 n 是什么?)

    Therefore, any practical algorithm you might choose has a running time that depends on what you consider the "average" case. Is there a restriction to the problem that I've either not considered or not had at my disposal? You seem rather sure it's an O(n3) problem. (Although what's n in this case?)

    更多推荐

    查找图中没有任何负前缀的最短路径

    本文发布于:2023-11-30 10:46:09,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1649701.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:没有任何   前缀   最短   图中   路径

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!