Pagini recente » Cod sursa (job #3258507) | Cod sursa (job #3243929) | Cod sursa (job #2222735) | Cod sursa (job #1454330) | Cod sursa (job #391263)
Cod sursa(job #391263)
program flip;
var a:array[1..16,1..16]of longint;
x,y:array[1..16]of -1..1;
n,m,i,j:byte;
s:longint;
procedure caut;
var aux:longint;
i,j:byte;
begin
aux:=0;
for i:=1 to n do
for j:=1 to m do
aux:=aux+(x[i]*y[j]*a[i,j]);
if aux>s then s:=aux;
end;
procedure go1(k:byte);
begin {m,y- coloane}
y[k]:=1;
if k=m then caut
else go1(k+1);
y[k]:=-1;
if k=m then caut
else go1(k+1);
end;
procedure go(k:byte);
begin
x[k]:=1; {n,x - linii}
if k=n then go1(1)
else go(k+1);
x[k]:=-1;
if k=n then go1(1)
else go(k+1);
end;
begin
assign(input,'flip.in'); reset(input);
read(n,m);
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
close(input);
s:=(-1)*maxlongint;
go(1);
assign(output,'flip.out'); rewrite(output);
write(s);
close(output);
end.