比赛 |
NOIP_5 |
评测结果 |
AAAAWAAAAA |
题目名称 |
Perform巡回演出 |
最终得分 |
90 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-24 21:27:40 |
显示代码纯文本
program day5_3;
var
n,k:integer;
f:array[0..1000,1..10] of int64;
g:array[1..10,1..10,0..30] of longint;
procedure init;
var
i,j,P:integer;
begin
for i:=1 to n do
for j:=1 to n do
if i<>j
then begin
read(g[i,j,0]);
for P:=1 to g[i,j,0] do
read(g[i,j,P]);
end;
end;
procedure main;
var
i,j,P:integer;
tm,val:longint;
begin
f[0,1]:=0;
for i:=1 to k-1 do
for j:=1 to n do
for P:=1 to n do
if P<>j
then if f[i-1,P]<>-1
then begin
val:=g[P,j,(i-1) mod g[P,j,0]+1];
if val<>0
then begin
tm:=f[i-1,P]+val;
if (tm<f[i,j]) or (f[i,j]=-1)
then f[i,j]:=tm;
end;
end;
for j:=1 to n do
if j<>n
then
if f[k-1,j]<>-1
then
begin
val:=g[j,n,(k-1) mod g[j,n,0]+1];
if (f[k,n]=-1) or (f[k-1,j]+val<f[k,n])
then f[k,n]:=f[k-1,j]+val;
end;
if f[k,n]=-1 then writeln(0)
else writeln(f[k,n]);
end;
begin
assign(input,'candy.in');
assign(output,'candy.out');
reset(input); rewrite(output);
read(n,k);
while (n<>0) or (k<>0) do begin
fillchar(g,sizeof(g),0);
fillchar(f,sizeof(f),$FF);
init;
main;
read(n,k);
end;
close(input); close(output);
end.