比赛 |
20101110 |
评测结果 |
AAWWWWWWWWWWWWWWWWWW |
题目名称 |
移动服务 |
最终得分 |
10 |
用户昵称 |
ZhouZn1 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 21:20:23 |
显示代码纯文本
program zzn;
var
n,i,j,l,ans:longint;
c:array[1..200,1..200]of longint;
a:array[1..10000]of longint;
procedure init;
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(c[i,j]);
readln;
end;
for i:=1 to n do read(a[i]);
end;
procedure closef;
begin
close(input);
close(output);
end;
procedure dep(x,y,z,d:integer;cost:longint);
begin
if d>n then
begin
if cost<ans then ans:=cost;
exit;
end;
dep(a[d],y,z,d+1,cost+c[x,a[d]]);
dep(x,a[d],z,d+1,cost+c[y,a[d]]);
dep(x,y,a[d],d+1,cost+c[z,a[d]]);
end;
procedure main;
begin
ans:=maxlongint;
dep(1,2,3,1,0);
writeln(ans);
end;
procedure main2;
var
k,s,x,min:longint;
xx:array[1..3]of integer;
begin
ans:=0;
xx[1]:=1;xx[2]:=2;xx[3]:=3;
for i:=1 to n do
begin
min:=maxlongint;
for j:=1 to 3 do
if min>c[xx[j],a[i]] then
begin
x:=j;
min:=c[xx[j],a[i]];
end;
inc(ans,c[xx[x],a[i]]);
xx[x]:=a[i];
end;
writeln(ans);
end;
begin
init;
if n<=14 then main else
main2;
closef;
end.