Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //program Ilya;
- //uses
- // System.SysUtils;
- Type
- TArray = array[1..10, 1..10] of Longint;
- TTArray = array[1..100] of longint;
- var
- i, j, n, m, max, x1, x2, y1, y2, nnn: longint;
- a, b: TArray;
- xx,yy: TTArray;
- procedure rec(i, j: Longint; b: TArray; sum: Longint; x,y: TTArray; nn:longint);
- begin
- if (i < 1) or (i > n) or (j < 1) or (j > m) then
- exit;
- if b[i, j] = 1 then
- exit;
- b[i, j] := 1;
- sum := sum + a[i, j];
- inc(nn);
- x[nn] := i;
- y[nn] := j;
- if (i = x2) and (j = y2) 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);
- rec(i - 1, j, b, sum, x, y, nn);
- rec(i, j + 1, b, sum, x, y, nn);
- rec(i, j - 1, b, sum, x, y, nn);
- end;
- var
- Count: Integer;
- begin
- max := -999999;
- Count := 0;
- WriteLn('Введите размерность');
- readln(n, m);
- WriteLn('Введите Элементы');
- for i := 1 to n do
- for j := 1 to m do
- begin
- Inc(Count);
- a[i,j] := Count;
- end;
- for i := 1 to n do
- begin
- for j := 1 to m do
- Write(a[i,j], ' ');
- Writeln;
- end;
- WriteLn('Введите Координаты');
- 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]);
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement