pascal程序语言问题
varn,i,j:integer;a:array[1..100,1..100]ofinteger;functionsolve(x,y:integer):integer;v...
var
n,i,j:integer;
a:array[1..100,1..100] of integer;
function solve(x,y:integer):integer;
var
n,v:integer;
begin
if x=n then
begin
solve:=a[x,y];
exit;
end;
u:=solve(x+1,y);
v:=solve(x+1,y+1);
if u>v then
solve:=a[x,y]+u
else
solve:=a[x,y]+v;
end;
begin
readln(n);
for i:=1 to n do
for j:=1 to i do
read(a[i,j]);
writeln(solve(1,1));
end
输入:
5
2
-1 4
2 -1 -2
-1 6 4 0
3 2 -1 5 8
输出:_______ 展开
n,i,j:integer;
a:array[1..100,1..100] of integer;
function solve(x,y:integer):integer;
var
n,v:integer;
begin
if x=n then
begin
solve:=a[x,y];
exit;
end;
u:=solve(x+1,y);
v:=solve(x+1,y+1);
if u>v then
solve:=a[x,y]+u
else
solve:=a[x,y]+v;
end;
begin
readln(n);
for i:=1 to n do
for j:=1 to i do
read(a[i,j]);
writeln(solve(1,1));
end
输入:
5
2
-1 4
2 -1 -2
-1 6 4 0
3 2 -1 5 8
输出:_______ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询