Advertisement
MadCortez

Untitled

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