What is a fu#^ing trick? I cannot AC this prog. (+). It is a simple DP
CONST Dim = 31;
INF = 1000000000;
VAR D:Array[0..Dim,0..Dim,0..Dim] of longint;
P:Array[1..Dim] of integer;
R:Array[0..Dim,0..Dim] of longint;
NL:integer;
PROCEDURE ReadData;
var K,i,j:integer;
begin
for i:=0 to Dim do
for j:=0 to Dim do
for k:=0 to Dim do D[i,j,k]:=INF;
readln(NL);
for i:=1 to NL do
begin
readln(P[i]);
for j:=1 to P[i] do
begin
repeat
read(K);
if K=0 then break;
read(D[i-1,K,j]);
until false;
readln;
end;
readln;
end;
end;
PROCEDURE Solve;
var Best,L,k,i,j,dd:longint;
begin
for i:=0 to Dim do
for j:=0 to Dim do R[i,j]:=INF;
for i:=1 to P[1] do R[1,i]:=D[0,1,i];
for L:=1 to NL-1 do
for j:=1 to P[L] do
if R[L,j]<>INF then
for k:=1 to P[L+1] do
begin
dd:=R[L,j]+D[L,j,k];
if dd<R[L+1,k] then R[L+1,k]:=dd;
end;
Best:=INF;
for i:=1 to P[NL] do
if R[NL,i]<Best then Best:=R[NL,i];
writeln(Best);
end;
BEGIN
ReadData;
Solve;
END.
Re: What is a fu#^ing trick? I cannot AC this prog. (+). It is a simple DP
Posted by
Pasha 24 Jul 2004 23:07
First, don't waist forum by bad words. Second, Your programm is AC, so don't worry, be happy.