比赛 NOIP_5 评测结果 AAAAAAAAAA
题目名称 Perform巡回演出 最终得分 100
用户昵称 francis 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-24 21:41:01
显示代码纯文本
program candy;
const
fin='candy.in';
fou='candy.out';
var
f:array[0..1000,1..10]of longint;
a:array[1..10,1..10,1..30]of longint;
d:array[1..10,1..10]of longint;
po:array[1..10,1..10]of longint;
p,i,j,n,k:longint;
f1,f2:text;

procedure init;
begin
read(f1,n,k);
if (n=0)and(k=0) then begin close(f1); close(f2); halt; end;
for i:=1 to n do
for j:=1 to n do
if i<>j then
begin
 read(f1,d[i,j]);
 for p:=1 to d[i,j] do
 read(f1,a[i,j,p]);
end;
for i:=1 to n do
f[0,i]:=999999999;
f[0,1]:=0;
for i:=1 to k do
for j:=1 to n do
f[i,j]:=999999999;
end;

procedure main;
begin
for i:=1 to k do
begin
 for j:=1 to n do
 for p:=1 to n do
 if j<>p then
      begin
       inc(po[j,p]);
       if po[j,p]>d[j,p] then po[j,p]:=1;
      end;
 for j:=1 to n do
 for p:=1 to n do
 if (p<>j)and(a[p,j,po[p,j]]<>0) then
   begin
    if f[i,j]>f[i-1,p]+a[p,j,po[p,j]] then
    f[i,j]:=f[i-1,p]+a[p,j,po[p,j]];
   end;
end;
end;

begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
while 1<>0 do
begin
 init;
 main;
 if f[k,n]>=999999999 then f[k,n]:=0;
 writeln(f2,f[k,n]);
end;
end.