program wassage;
var a:array[0..50,0..50]of integer;
f:array[-1..101,0..50,0..50] of integer;
i,j,k,m,n,x,y1,y2,max:integer;
procedure max4(i,j,k,m:integer);------比四组取大
begin
if i<j then i:=j;
if i<k then i:=k;
if i<m then i:=m;
max:=i;
end;
function min2(i,j:integer):integer;-----两组取小;
begin
if i<=j then exit(i)
else exit(j);
end;
begin
read(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);--------读入
f[0,1,1]:=0;-----------初始化(还有这另一种是这样初始化的:
for i:=1 to min2(m,n)-1 do
begin
f[i,i+1,1]:=f[i-1,i,1]+a[1,i+1]+a[i+1,1];
f[i,1,i+1]:=f[i-1,1,i]+a[1,i+1]+a[i+1,1];
end;
for i:=1 to m-1 do
f[i,i+1,i+1]:=f[i-1,i,i]+a[i+1,1];
for i:=1 to n-1 do
f[i,1,1]:=f[i-1,1,1]+a[i,i+1];)
f[1,2,1]:=a[1,2]+a[2,1];
f[1,1,2]:=f[1,2,1];
for k:=1 to m+n-2 do-----步数
for i:=1 to n do
for j:=1 to n do
begin
y1:=k+2-i;
y2:=k+2-j;
max4(f[k-1,i,j],f[k-1,i-1,j-1],f[k-1,i-1,j],f[k-1,i,j-1]);------转移方程
f[k,i,j]:=max;
if i=j
then inc(f[k,i,j],a[i,y1])
else begin
inc(f[k,i,j],a[i,y1]);
inc(f[k,i,j],a[j,y2]);
end;
end;
writeln(f[m+n-2,n,n]);--输出
end.
有么那位牛热播帮看一下,我已经改很久了,不知哪出错了,看我打这么多得份上能不能详解下都有哪的思路有问题。谢谢
var a:array[0..50,0..50]of integer;
f:array[-1..101,0..50,0..50] of integer;
i,j,k,m,n,x,y1,y2,max:integer;
procedure max4(i,j,k,m:integer);------比四组取大
begin
if i<j then i:=j;
if i<k then i:=k;
if i<m then i:=m;
max:=i;
end;
function min2(i,j:integer):integer;-----两组取小;
begin
if i<=j then exit(i)
else exit(j);
end;
begin
read(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);--------读入
f[0,1,1]:=0;-----------初始化(还有这另一种是这样初始化的:
for i:=1 to min2(m,n)-1 do
begin
f[i,i+1,1]:=f[i-1,i,1]+a[1,i+1]+a[i+1,1];
f[i,1,i+1]:=f[i-1,1,i]+a[1,i+1]+a[i+1,1];
end;
for i:=1 to m-1 do
f[i,i+1,i+1]:=f[i-1,i,i]+a[i+1,1];
for i:=1 to n-1 do
f[i,1,1]:=f[i-1,1,1]+a[i,i+1];)
f[1,2,1]:=a[1,2]+a[2,1];
f[1,1,2]:=f[1,2,1];
for k:=1 to m+n-2 do-----步数
for i:=1 to n do
for j:=1 to n do
begin
y1:=k+2-i;
y2:=k+2-j;
max4(f[k-1,i,j],f[k-1,i-1,j-1],f[k-1,i-1,j],f[k-1,i,j-1]);------转移方程
f[k,i,j]:=max;
if i=j
then inc(f[k,i,j],a[i,y1])
else begin
inc(f[k,i,j],a[i,y1]);
inc(f[k,i,j],a[j,y2]);
end;
end;
writeln(f[m+n-2,n,n]);--输出
end.
有么那位牛热播帮看一下,我已经改很久了,不知哪出错了,看我打这么多得份上能不能详解下都有哪的思路有问题。谢谢