📄 fordyn.m
字号:
function [pathlist,cost] = fordyn(G,W)
%
% Do forward dynamic programing
%
% function [pathlist,cost] = fordyn(G,W)
%
% G = list of next vertices
% W = list of costs to next vertices
%
% pathlist = list of paths through graphs
% cost = cost of the paths
% Copyright 1999 by Todd K. Moon
[m,n] = size(G); % n = number of vertices
n = n+1;
costs(n) = 0;
for j=n-1:-1:1
c = W{j}+costs(G{j});
[minc,idx] = min(c);
costs(j) = minc;
savevertex(j) = G{j}(idx);
end
cost = costs(1);
pathlist(1) = 1;
for j=2:n
pathlist(j) = savevertex(pathlist(j-1));
if(pathlist(j) == n)
break;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -