您的位置:首页 > 其它

(ssl1636)城市交通

2017-03-01 16:32 239 查看
城市交通
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

11
0 5 3 0 0 0 0 0 0 0 0
5 0 0 1 6 3 0 0 0 0 0
3 0 0 0 8 0 4 0 0 0 0
0 1 0 0 0 0 0 5 6 0 0
0 6 8 0 0 0 0 5 0 0 0
0 3 0 0 0 0 0 0 0 8 0
0 0 4 0 0 0 0 0 0 3 0
0 0 0 5 5 0 0 0 0 0 3
0 0 0 6 0 0 0 0 0 0 4
0 0 0 0 0 8 3 0 0 0 3
0 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
);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: