Pagini recente » Cod sursa (job #2571701) | Cod sursa (job #2243106) | Cod sursa (job #282211) | Cod sursa (job #701248) | Cod sursa (job #944410)
Cod sursa(job #944410)
type tabel=array[1..17,1..17] of longint;
tab2=array[1..33] of longint;
var a,b:text;
n,m,c,d,max:integer;
t,u:tabel;
s:tab2;
function calcul:longint;
var i,j:longint;
begin
for i:=1 to n do
if s[i]=1 then
for j:=1 to m do
u[i,j]:=t[i,j]*(-1)
else
for j:=1 to m do
u[i,j]:=t[i,j];
for i:=n+1 to m+n do
if s[i]=1 then
for j:=1 to n do
u[j,i-n]:=t[j,i-n]*(-1)
else
for j:=1 to n do
if u[j,i-n]=0 then
u[j,i-n]:=t[j,i-n];
calcul:=0;
for i:=1 to n do
for j:=1 to m do
calcul:=calcul+u[i,j];
end;
procedure f(k:longint);
var i:integer;
begin
if k>0 then
begin
if k-1=n+m then
begin
if calcul>max then max:=calcul;
end
else
for i:=0 to 1 do
begin
s[k]:=i;
f(k+1);
end;
end;
end;
begin
assign(a,'flip.in'); reset(a);
assign(b,'flip.out'); rewrite(b);
read(a,n,m);
for c:=1 to n do
for d:=1 to m do
begin
read(a,t[c,d]);
end;
max:=0;
f(1);
writeln(b,max);
close(a);
close(b);
end.