(ssl1636)城市交通

来源:互联网 发布:octave mac 编辑:程序博客网 时间:2024/04/29 09:41

城市交通

Time Limit:1000MS  Memory Limit:65536K
Total Submit:101 Accepted:91

Description

  有n个城市,编号1~n,有些城市之间有路相连,有些则没有,有路则当然有一个距离。现在规定只能从编号小的城市到编号大的城市,问你从编号为1的城市到编号为n的城市之间的最短距离是多少?

Input

先输入一个n,表示城市数,n小于100。 
下面的n行是一个n*n的邻接矩阵map[i,j],其中map[i,j]=0表示城市i和城市j之间没有路相连,否则为两者之间的距离。

Output

输出格式:一个数,表示最少要多少时间。 
输入数据保证可以从城市1飞到城市n。 

Sample Input

110 5 3 0 0 0 0 0 0 0 05 0 0 1 6 3 0 0 0 0 03 0 0 0 8 0 4 0 0 0 00 1 0 0 0 0 0 5 6 0 00 6 8 0 0 0 0 5 0 0 00 3 0 0 0 0 0 0 0 8 00 0 4 0 0 0 0 0 0 3 00 0 0 5 5 0 0 0 0 0 30 0 0 6 0 0 0 0 0 0 40 0 0 0 0 8 3 0 0 0 30 0 0 0 0 0 0 3 4 3 0

Sample Output

13

Source

elba

var f:array[1..100]of longint; a:array[1..100,1..100]of longint; i,j,n,min:longint;begin read(n); for i:=1 to n do  for j:=1 to n do   read(a[i,j]); for i:=2 to n do//选排  begin   min:=10000;   for j:=1 to i-1 do    if a[j,i]<>0 then//如果他这条路可以走(飞)     if f[j]+a[j,i]<=min then min:=f[j]+a[j,i];//打擂台   f[i]:=min;//装的是去这个城市到起点最短的路程  end; write(f[n]);end.


0 0
原创粉丝点击