记录编号 2769 评测结果 AAAAAEEEEE
题目名称 Perform巡回演出 最终得分 50
用户昵称 Gravatar苏轼 是否通过 未通过
代码语言 Pascal 运行时间 0.038 s
提交时间 2008-09-27 13:10:08 内存使用 118.46 MiB
显示代码纯文本
program cch(input,output);
var
 f:array[0..10,1..1000] of int64;
 b:array[1..1000] of longint;
 d:array[1..1000,1..1000] of longint;
 a:array[1..1000,1..1000,1..30] of longint;
 n,k,i,j,q,x,y,z:longint;

function min(x,y:longint):longint;
begin
 if x>y then exit(y)
        else exit(x);
end;

begin
 assign(input,'candy.in');
 assign(output,'candy.out');
 reset(input);
 rewrite(output);
 readln(n,k);
 while not ((n=0)and(k=0)) do
  begin
   for i:=1 to n do b[i]:=0;
   f[0,1]:=0;
   for i:=2 to n do f[0,i]:=maxlongint;
   y:=1; z:=0;
   for i:=1 to n*(n-1) do
    begin
     inc(z);
     if z=n then begin inc(y); z:=1; end;
     inc(b[y]);
     if b[y]=y then inc(b[y]);
     read(d[y,b[y]]);
     for j:=1 to d[y,b[y]] do read(a[y,b[y],j]);
    end;
   for i:=1 to k do
    for j:=1 to n do
     begin
      f[i,j]:=maxlongint;
      for q:=1 to n do
       if (j<>q)and(f[i-1,q]<>maxlongint) then
       begin
        x:=i mod d[q,j];
        if x=0 then x:=d[q,j];
        if (a[q,j,x]<>0) then
          f[i,j]:=min(f[i,j],f[i-1,q]+a[q,j,x]);
       end;
     end;
   if f[k,n]=maxlongint then writeln(0)
                        else writeln(f[k,n]);
   readln(n,k);
  end;
  close(input);
  close(output);
end.