1004请大神帮忙查错
  • 板块灌水区
  • 楼主clyoyo
  • 当前回复4
  • 已保存回复4
  • 发布时间2015/1/14 20:54
  • 上次更新2023/10/22 10:17:35
查看原帖
1004请大神帮忙查错
4897
clyoyo楼主2015/1/14 20:54

有一个点过不了

var n,i,j,v,ans:longint;
    f,a:array[0..9,0..9] of longint;
function max(a,b:longint):longint;
begin
  if a>b then exit(a)
  else exit(b);
end;
begin
  readln(n);
  while true do
  begin
    readln(i,j,v);
    if (i=0) and (j=0) and (v=0) then
      break;
    a[i,j] := v;
  end;
  //求解第一次
  for i:=1 to n do
    for j:=1 to n do
      f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
  ans := f[n,n];
  //回溯走过的路置0
  while true do
  begin
    a[i,j] := 0;
    if (i=1) and (j=1) or (f[i,j]=0) then break;
    if f[i-1,j]>f[i,j-1] then
      dec(i)  
    else
      dec(j);
  end;
  //求解第二次
  for i:=1 to n do
    for j:=1 to n do
      f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
  writeln(ans+f[n,n]);
end.
  while true do
  begin
    a[i,j] := 0;
    if (i=1) and (j=1) or (f[i,j]=0) then break;
    if f[i-1,j]>f[i,j-1] then
      dec(i)  
    else
      dec(j);
  end;
  for i:=1 to n do
    for j:=1 to n do
      f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
  writeln(ans+f[n,n]);
end.
2015/1/14 20:54
加载中...