- 分享
- 2009-02-04 10:16:27 @
var n,i,j,k:longint;
data:array[1..8,1..8] of longint;
f:array[0..50,0..50,0..50] of longint;
a,b,c:longint;
function min(v1,v2:longint):longint;
begin if v1>v2 then exit(v2);
exit(v1);
end;
function max(v1,v2,v3,v4:longint):longint;
begin if (v4>=v1) and (v4>=v3) and (v4>=v2) then exit(v4);
if (v3>=v1) and (v3>=v2) and (v3>=v4) then exit(v3);
if (v2>=v1) and (v2>=v3) and (v2>=v4) then exit(v2);
if (v1>=v2) and (v1>=v3) and (v1>=v4) then exit(v1);
end;
procedure init;
begin readln(n);
readln(a,b,c);
while a0 do
begin
readln(a,b,c);
if a=0 then exit;
data[a,b]:=c;
end;
end;
procedure main;
begin fillchar(f,sizeof(f),0);
for k:=1 to 2*n-1 do
begin
for i:=1 to min(n,k) do
for j:=i+1 to min(n,k) do
f[k,i,j]:=max(f[k-1,i,j],f[k-1,i-1,j],f[k-1,i-1,j-1],f[k-1,i,j-1])+data+data[j,k-j+1];
end;
writeln(f[2*n-1,n,n-1]+f[2*n-1,n-1,n]);
end;
begin
init;
main;
end.
百思不得其解 Why wrong answer? Why?