与边缘的指定数量的最短路径最短、路径、边缘、数量

2023-09-11 05:22:19 作者:我背好痒是不是要变喰种

即时寻找一种算法,发现在包含边缘的指定数n的曲线图的两个顶点(i和j)之间的最短路径。我有一个动态的方案,着眼于最短路径与n-1个边缘目标,但我怎么能肯定是被发现的最短路径开始于我?

i'm looking for an algorithm that finds the shortest path between two vertices (i and j) in a graph that contains a specified number of edges, n. i have a dynamic program that looks at the shortest path to the destination with n-1 edges, but how can i be sure that the shortest path being found starts at i?

推荐答案

我猜边有不同的成本/长度和约束是有n条边,和所有路径中从i到j有n个个体边缘,该目标是找到一个具有至少总成本/长度

I guess the edges have different costs / lengths and that the constraint is that there are n edges, and among all paths from i to j that have exactly n individual edges, the goal is to find the one that has least total cost / length.

如果你做到这一点使用动态编程,复发是

If you do this using dynamic programming, the recurrences are

spath(f, t, n): --- returns shortest path from 'f' to 't' that has 'n' edges

spath(x, x, 0) = [x] --- path that has only one vertex
spath(x, y, 0) = NO PATH --- when x != y

spath(f, t, n) =
  min cost path over (x is any node that is connected to t):
     spath(f, x, n-1) + [t] (x can be appended because there is edge x - t)