记录编号 21520 评测结果 AAAAAAAAAAWAWWAAWWWT
题目名称 移动服务 最终得分 65
用户昵称 GravatarAchilles 是否通过 未通过
代码语言 Pascal 运行时间 2.724 s
提交时间 2010-11-11 09:39:55 内存使用 0.57 MiB
显示代码纯文本
program service;
var
  n,l,i,j,k,now,last,t,lt:longint;
  tab:array[1..200,1..200]of longint;
  sz:array[0..1,1..200,1..200]of longint;
begin
  assign(input,'service.in');
  assign(output,'service.out');
  reset(input);
  rewrite(output);
  readln(n,l);
  for i:=1 to n do
  begin
    for j:=1 to n do
      read(tab[i,j]);
    readln;
  end;
  for i:=1 to n do
    for j:=1 to n do
      sz[0,i,j]:=2000000000;
  sz[0,1,2]:=0;
  last:=0;
  now:=1;
  lt:=3;
  for i:=1 to l do
  begin
    read(t);
    for j:=1 to n do
      for k:=1 to n do
        sz[now,j,k]:=2000000000;
    for j:=1 to n do
      for k:=1 to n do
      begin
        if sz[last,j,k]+tab[lt,t]<sz[now,j,k] then
          sz[now,j,k]:=sz[last,j,k]+tab[lt,t];
        if sz[last,j,k]+tab[k,t]<sz[now,j,lt] then
          sz[now,j,lt]:=sz[last,j,k]+tab[k,t];
        if sz[last,j,k]+tab[j,t]<sz[now,lt,k] then
          sz[now,lt,k]:=sz[last,j,k]+tab[j,t];
      end;
    lt:=t;
    last:=(last+1)mod 2;
    now:=(now+1)mod 2;
  end;
  t:=2000000000;
  for i:=1 to n do
    for j:=1 to n do
      if sz[last,i,j]<t then t:=sz[last,i,j];
  writeln(t);
  close(input);
  close(output);
end.