我一直在尝试使用Floyd-Marshall算法来解决运动问题,但是它一直仅返回零矩阵。这是代码:
// Adjacency matrix
let am = [[0,0,0,1,1,1],
[0,0,1,0,1,0],
[0,1,0,1,0,1],
[1,0,1,0,0,0],
[1,1,0,0,0,0],
[1,0,1,0,0,0]]
// Floyd-Warshall algorithm
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++) {
if (am[i][j] > am[i][k] + am[k][j]) {
am[i][j] = am[i][k] + am[k][j];
}
}
}
}
return am;
返回
[[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0]]
我在做什么错了?