Advertisement
MadCortez

Untitled

Oct 31st, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.08 KB | None | 0 0
  1. Type
  2.    TArray = array[1..1000, 1..1000] of Longint;
  3.    TTArray = array[1..1000] of longint;
  4. var
  5.    i, j, n, m, max, x1, x2, y1, y2, nnn: longint;
  6.    a, b, c: TArray;
  7.    xx,yy: TTArray;
  8. procedure rec(i, j: Longint; b: TArray; sum: Longint; x,y: TTArray; nn:longint);
  9. begin
  10.    if (i < 1) or (i > n) or (j < 1) or (j > m) then exit;
  11.    if c[i, j] = 1 then exit;
  12.    if b[i, j] = 2 then
  13.    begin
  14.       c[i, j] := 1;
  15.       exit;
  16.    end;
  17.    inc(b[i, j]);
  18.    sum := sum +a[i, j];
  19.    inc(nn);
  20.    x[nn] := i;
  21.    y[nn] := j;
  22.    if (i = x2) and (j = y2) then
  23.       if sum > max then
  24.       begin
  25.          max := sum;
  26.          xx := x;
  27.          yy := y;
  28.          nnn := nn;
  29.          exit;
  30.       end;
  31.    rec(i + 1, j, b, sum, x, y, nn);
  32.    rec(i - 1, j, b, sum, x, y, nn);
  33.    rec(i, j + 1, b, sum, x, y, nn);
  34.    rec(i, j - 1, b, sum, x, y, nn);
  35. end;
  36. begin
  37.    readln(n, m);
  38.    for i := 1 to n do
  39.       for j := 1 to m do
  40.          read(a[i,j]);
  41. readln(x1, y1);
  42. readln(x2, y2);
  43. rec(x1, y1, b, 0, xx, yy, 0);
  44. writeln(max);
  45. for i := 1 to nnn do
  46.    writeln(xx[i], ' ', yy[i]);
  47. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement