参考:
Single-Source Shortest Path:Bellman-Ford Algorithm
SPFA——基于Bellman-Ford的队列优化
How is the Bellman Ford algorithm a case of dynamic programming?
Shortest Path and Dynamic Programming Algorithms
算法简介
Bellman-Ford算法可以用于含有负权重的有向图中单源最短路径计算。他的本质是一种暴力求解,同时也运用了动态规划的思想。
算法思想
Bellman-Ford算法的思路是对于有N个节点的图,给定起点s,只要通过N-1轮更新(松弛操作),我们必定可以得到任意点到s点的最小代价dis。具体的证明在《算法》(第四版)里面有介绍。简要叙述如下:
1.将所有节点分为两类:已知最短距离的节点和剩余节点。