% matrix C gives link costs (time, money, ...) % C(i,j) is cost to go from j to i. % V is col vector that stores the min-cost-to-go info % V(i) is min cost to get to node 1 from node i % i.e. node 1 is target % % DP says V(j) = min_i (C(i,j)+V(i)) for i>1 % and V(1)=0 % define C: C=[ 0 11 5 31 13 28 46 52 5 49; 19 26 1 42 70 25 59 18 49 24; 25 33 27 26 63 25 10 16 42 24; 71 28 21 26 41 56 6 25 70 12; 14 27 28 7 48 47 4 48 22 37; 9 40 51 44 62 54 58 40 10 11; 53 41 52 16 34 4 19 0 52 71; 66 2 21 9 31 94 23 33 54 1; 2 33 29 10 34 31 12 47 14 13; 19 78 4 50 26 2 41 31 53 23]; % the following two lines does one iteration of the DP equation: n = size(C,1); V = min(C+V*ones(1,n))'; V(1)=0;