https://zhuanlan.zhihu.com/p/33162490
Floyd
一种基于动态规划的多源最短路算法
private void floyd() {
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
System.out.println(i + " " + j + ":" + a[i][j]);
}
}
}
状态转移方程:f[k][i][j] = min(f[k-1][i][k],f[k-1][i][k]+f[k-1][k][j]),然后用滚动数组优化
空间复杂度O(n^2),时间复杂度O(n^3)
Dijkstra算法
一种经典的基于贪心的单源最短路算法,其要求