floyd triple loop Why must the outermost layer is K

Why Floyd algorithm k on the outermost layer? - know almost https://www.zhihu.com/question/30955032
overwhelmingly answer:

 

 

To briefly summarize: K not on the outermost must be wrong, but in the case of certain data may be relatively water AC
nature floyd is DP, K represents the DP stage, after this point or not slack after this point, if you put K on the inside, there may be some points there is no slack to, the demand side would not be the optimal solution

The following examples:

 

 

from to cost

   1   2    4
   2   3    5
   3   4    3
   4   5    2
   1   5    1

If the order of i, j, k is to traverse, then there will be the following:
Suppose the running J =. 3. 1 = I
K = l, l> = INF. 3
K = the 2,1->. 9. 3 =
K = 3, 1-> 3:. 9
K = 4, or the same, would not normally be relaxed by from 4 to 1-> 3 do
but optimal solution is 1-> 5-> 4-> 3 = 6
Why is this so, because at a distance of 1-> 3 calculation, we did not go slack from 1-> 4, the cause can not go slack by 4 1-> 3

 

Guess you like

Origin www.cnblogs.com/simaomao/p/12292903.html