Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type
- TArray = array[1..1000, 1..1000] of Longint;
- TTArray = array[1..1000] of longint;
- var
- i, j, n, m, max, x1, x2, y1, y2, nnn, k: longint;
- a, b, c: TArray;
- xx,yy: TTArray;
- ss: array[1..1000] of string;
- procedure rec(i, j: Longint; b: TArray; sum: Longint; x,y: TTArray; nn:longint; s:string);
- var h: longint;
- s1: string;
- begin
- if (i < 1) or (i > n) or (j < 1) or (j > m) then exit;
- if b[i, j] = 2 then exit;
- str(i, s1);
- s := s + s1;
- str(j, s1);
- s := s + s1;
- for h := 1 to k do
- if ss[h] = s then exit;
- inc(k);
- ss[k] := s;
- writeln(i,' ',j);
- inc(b[i, j]);
- sum := sum + a[i, j];
- inc(nn);
- x[nn] := i;
- y[nn] := j;
- if (i = x2) and (j = y2) and (b[i, j] = 2) then
- if sum > max then
- begin
- max := sum;
- xx := x;
- yy := y;
- nnn := nn;
- exit;
- end;
- rec(i + 1, j, b, sum, x, y, nn, s);
- rec(i - 1, j, b, sum, x, y, nn, s);
- rec(i, j + 1, b, sum, x, y, nn, s);
- rec(i, j - 1, b, sum, x, y, nn, s);
- end;
- begin
- readln(n, m);
- for i := 1 to n do
- for j := 1 to m do
- read(a[i,j]);
- readln(x1, y1);
- readln(x2, y2);
- rec(x1, y1, b, 0, xx, yy, 0, '');
- writeln(max);
- for i := 1 to nnn do
- writeln(xx[i], ' ', yy[i]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement