Pagini recente » Cod sursa (job #2101401) | Cod sursa (job #1422503) | Cod sursa (job #3040111) | Cod sursa (job #1399030) | Cod sursa (job #1422934)
var n,m,sum:longint;
a,b:array[1..16,1..16] of longint;
procedure bin(s:string);
var i,j,k,s1,s2:longint;
begin
if length(s)=n then begin
for i:=1 to n do
if s[i]='1' then
for j=1 to m do
b[i,j]:=-a[i,j]
else b[i,j]:=a[i,j];
for k:=1 to m do begin
s1:=0;
s2:=0;
for j:=1 to n do
if a[j,k]>=0 then s1:=s1+a[j,k]
else s2:=s2-a[j,k];
if s2>s1 then
for j:=1 to n do
b[j,k]:=-a[j,k];
for i:=1 to n do
for j:=1 to m do
k:=k+a[i,j];
if k>sum then sum:=k;
end else begin
bin(s+'0');
bin(s+'1');
end;
end;
begin
// assign(input,'input.in');
assign(input,'flip.in');
assign(output,'flip.out');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
sum:=0;
bin('');
writeln(sum);
end.