讨论 / Need Help~
woshiniba 2009-02-12 19:43:00
点我顶贴 收藏 删除
314 选数,恳请指教:

附 [color=red]0分[/color]代码:

program rq314;

var

f:array [1..19,0..11,0..11] of longint;

num:array [1..19,0..11] of longint;

n,a,b,c,i,x,y,p,q,j:longint;

function max4(a,b,c,d:longint):longint;

begin

if a>b then max4:=a

else max4:=b;

if c>max4 then max4:=c;

if d>max4 then max4:=d;

end;

function max2(a,b:longint):longint;

begin

if a>b then exit(a)

else exit(b);

end;

begin

readln(n);

for i:=1 to n do

begin

readln(a,b,c);

p:=a+b-1;

if p>n then q:=b-(p-n)

else q:=b;

num[p,q]:=c;

end;

readln(a,b,c);

f[1,1,1]:=num[1,1];

p:=0; q:=0;

for i:=2 to 2*n-1 do

begin

for x:=1 to n-abs(i-n) do

for y:=1 to n-abs(i-n) do

begin

p:=max4(f[i-1,x-1,y-1],f[i-1,x-1,y],f[i-1,x,y-1],f[i-1,x,y]);

if x=y then f[i,x,y]:=p+num[i,x]

else f[i,x,y]:=p+num[i,x]+num[i,y];

end;

end;

writeln(f[2*n-1,1,1]);

readln;

end.

#1 woshiniba@2009-02-10 20:18:00
回复 删除
↑UP↑
#2 woshiniba@2009-02-12 19:43:00
回复 删除
UP~~again
查看更多回复
提交回复