![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
最短路径
Bread Sir
记录算法之路
展开
-
图—单源最短路径算法(一)Bellman-Ford算法
Bellman-Ford算法这个算法解决的是一般情况下的单源最短路径问题,即可带负权值,但是缺点是效率低。Bellman-Ford算法返回一个布尔值,以表明是否存在一个从源结点可以到达的权重为负值的环路。 它通过对边进行松弛操作来渐进地降低从源结点s到每个结点v的最短路径的估计值v.d,直到该估计值与实际的最短路径权重δ(s,v)相同时为止。伪代码如下:BELLMAN-FORD(G,W,s)原创 2017-04-11 19:52:12 · 525 阅读 · 0 评论 -
图—单源有权最短路径概述——《算法导论》
背景:在图的BFS中我整理了用BFS求最短路径的方法,但是前提是这个图必须是无权的,但是不是所有图的路径距离都是无权的(单位权值),甚至大多数的图都是有权的,因为很多都是联系实际的问题,而在现实中,两个点之间距离是有权值的,比如实际上的距离,比如时间、成本、罚款、损失等等等等,都可以作为权值,所以我们需要解决带权值的最短路问题。最短路径问题:分单源最短路径和多源最短路径: 我着重学习了一下单源最短原创 2017-04-11 16:42:19 · 632 阅读 · 0 评论 -
任意结点对最短路问题——Floyd-Warshall算法
在概述中,我们谈到最短路径的一个关键性质:最短路径的子路径也是最短路径。那么任意结点之间的最短路问题就可以通过这个性质利用DP来解决。任意结点对最短路问题分析:按照DP的三个步骤: 1.刻画最优解的结构特征: 定义dp[k][i][j]为只使用0~k和i,j的情况下,i到j的最短路长度。当k=0,则只使用i和j,则dp[0][i][j]=cost[i][j]。 2.递归地定义最优解: 只使用0~原创 2017-04-15 10:15:46 · 777 阅读 · 0 评论 -
POJ - 3268 Silver Cow Party(图论/dijkstra最短路)
问题描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-w原创 2017-04-24 20:09:29 · 269 阅读 · 0 评论 -
POJ - 3259 Wormholes (图论/floyd判断负圈)
问题描述 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time t原创 2017-04-24 20:06:11 · 821 阅读 · 0 评论 -
图—单源最短路径算法(二)Dijksta算法
Dijksta算法:Dijksta算法相比于Bellman-Ford算法,效率提高了许多,但是不能解决带有负权值的图,所以要根据具体问题采取相应的算法,即有负权值的图只能用Bellman-Ford算法,如果权值是非负的,那么我们就选择Dijksta算法,效率高嘛。分析:1.找到最短距离已经确定的顶点,从它出发更新相邻顶点的最短距离。 2.此后不需要再关心1中的“最短距离已经确定的顶点”。 在最开原创 2017-04-12 18:52:35 · 645 阅读 · 0 评论 -
POJ - 2139 Six Degrees of Cowvin Bacon(图论/无权最短路径BFS)
问题描述 The cows have been making movies lately, so they are ready to play a variant of the famous game “Six Degrees of Kevin Bacon”. The game works like this: each cow is considered to be zero degrees o原创 2017-04-24 20:13:23 · 337 阅读 · 0 评论 -
POJ - 3669 Meteor Shower(图论/BFS无权最短路)
问题描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to原创 2017-04-24 20:32:11 · 276 阅读 · 0 评论