Pagini recente » Cod sursa (job #2140832) | Cod sursa (job #3278963) | Cod sursa (job #918849) | Cod sursa (job #2884099) | Cod sursa (job #177459)
Cod sursa(job #177459)
var a,b,c:array[1..16,1..16] of longint;
n,m,i,j,smax:longint;
st:array[1..16] of -1..1;
f,g:text;
procedure verif(k:integer);
var i,j,ss,s:longint;
begin
for i:=1 to k do
if st[i]=-1 then c[i]:=b[i]
else c[i]:=a[i];
ss:=0;
for j:=1 to m do
begin
s:=0;
for i:=1 to n do s:=s+c[i,j];
if s<0 then ss:=ss-s
else ss:=ss+s;
end;
if ss>smax then smax:=ss;
end;
procedure gen(k:integer);
begin
if k=n+1 then verif(k-1)
else
begin
st[k]:=-1;
gen(k+1);
st[k]:=1;
gen(k+1);
end;
end;
begin
assign(f,'flip.in'); reset(f);
assign(g,'flip.out'); rewrite(g);
readln(f,n,m);
for i:=1 to n do
for j:=1 to m do
begin
read(f,a[i,j]);
b[i,j]:=-a[i,j];
end;
smax:=-maxlongint;
gen(1);
writeln(g,smax);
close(g);
end.