Skip to Content
算法技术手册(原书第2 版)
book

算法技术手册(原书第2 版)

by George T.Heineman, Gary Pollice, Stanley Selkow
August 2017
Intermediate to advanced
360 pages
8h 35m
Chinese
China Machine Press
Content preview from 算法技术手册(原书第2 版)
154
6
6.7.2 决方案
动态规划方法将会依序计算更小的子问题。考虑
G
的边:它们代表了两个顶点
u
v
间最短路径的长度,这条路径
不包含任何其他顶点
。因此,
dist[u][v]
矩阵首先被初始
化为
dist[u][u]
被设置为
0
(确认从顶点
u
到其自身的路径没有任何费用)。最后,
dist[u][v]
被设置为每条边
(
u
,
v
)
E
权值。在这个点上,
dist
矩阵包含了当前计算
出的点对
(
u
,
v
)
之间的最优最短路径。
接着考虑稍大一点的子问题,即计算任意点对
u
v
之间的最短路径,但是这条路径
许会包含顶点
v
1
。动态规划会检查每个顶点对
(
u
,
v
)
,检查是否存在路径
{
u
v
1
v
}
有比当前数字更小的总距离。在某些情况下
dist[u][v]
会依然是
,因为在
u
v
间还没有任何信息。而在其他时候,从
u
v
1
,再从
v
1
v
的路径和要比当前距离更好,
这时算法会在
dist[u][v]
记录新的总长度。接下去,再大一点的子问题是尝试解决
任意两个点对
u
v
之间的最短距离,但是
可能会包含
顶点
v
1
或者
v
2
。最终,算法会将
这些子问题不断扩展,直
dist[u][v]
阵中的结果包含任意两个顶点
u
v
之间的
最短路径,而这条路径也许会包含图中的任意顶点。
Floyd-Warshall
算法
计算的关键优化是判断
dist[u][k] + dist[k][v]
否小
dist[u][v]
注意,算法同样计算
pred[u][v]
阵,它用于“记住”新的从
u
v
的最短路径必须经过顶点
k
。例
6-6
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787111562221