比赛 |
20101110 |
评测结果 |
AATATTTTTTTTTTTTTTTT |
题目名称 |
移动服务 |
最终得分 |
15 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 20:20:37 |
显示代码纯文本
var
l,n,i,j,min:longint;
a:array[0..2000]of longint;
c:array[0..200,0..200]of longint;
procedure go(k,m,x,y,z:longint);
begin
if k=n+1 then
begin
if m<min then min:=m;
exit;
end;
if (a[k]<>x)and(a[k]<>y)and(a[k]<>z) then
begin
go(k+1,m+c[x,a[k]],a[k],y,z);
go(k+1,m+c[y,a[k]],x,a[k],z);
go(k+1,m+c[z,a[k]],x,y,a[k]);
exit;
end;
go(k+1,m,x,y,z);
end;
begin
assign(input,'service.in'); reset(input);
assign(output,'service.out'); rewrite(output);
readln(l,n);
for i:=1 to l do
for j:=1 to l do
read(c[i,j]);
for i:=1 to n do read(a[i]);
min:=maxlongint;
go(1,0,1,2,3);
writeln(min);
close(input);
close(output);
end.