记录编号 |
21590 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
移动服务 |
最终得分 |
100 |
用户昵称 |
belong.zmx |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
2.098 s |
提交时间 |
2010-11-11 20:23:39 |
内存使用 |
0.57 MiB |
显示代码纯文本
program mobilephone;
var
f:array[0..1,1..200,1..200]of longint;
d,mm,max,min,i,j,k,l,n,p,q:longint;
a:array[1..1000]of longint;
map:array[1..200,1..200]of longint;
begin
assign (input,'service.in');
reset (input);
assign (output,'service.out');
rewrite (output);
readln (l,n);
for i:=1 to l do
begin
for j:=1 to l do
read (map[i,j]);
readln
end;
for i:=1 to n do
read (a[i]);
readln;
for k:=0 to 1 do
for i:=1 to l do
for j:=1 to l do
f[k,i,j]:=maxlongint;
f[1,2,3]:=map[1,a[1]];
f[1,1,3]:=map[2,a[1]];
f[1,1,2]:=map[3,a[1]];
for k:=1 to n-1 do
begin
p:=k mod 2;
q:=(k+1)mod 2;
for i:=1 to l-1 do
for j:=i+1 to l do
if (a[k]<>i)and(a[k]<>j)and(f[p,i,j]<>maxlongint) then
begin
d:=f[p,i,j];
if d+map[a[k],a[k+1]]<f[q,i,j] then
f[q,i,j]:=d+map[a[k],a[k+1]];
if a[k]>j then
begin
max:=a[k];
mm:=j
end
else
begin
max:=j;
mm:=a[k]
end;
if d+map[i,a[k+1]]<f[q,mm,max] then
f[q,mm,max]:=d+map[i,a[k+1]];
if a[k]>i then
begin
max:=a[k];
mm:=i
end
else
begin
max:=i;
mm:=a[k]
end;
if d+map[j,a[k+1]]<f[q,mm,max] then
f[q,mm,max]:=d+map[j,a[k+1]]
end;
for i:=1 to l-1 do
for j:=i+1 to l do
f[p,i,j]:=maxlongint
end;
min:=maxlongint;
p:=n mod 2;
for i:=1 to l do
for j:=i+1 to l do
if (a[n]<>i)and(a[n]<>j)and(f[p,i,j]<min) then
min:=f[p,i,j];
writeln (min);
close (input);
close (output)
end.