Pagini recente » Cod sursa (job #821605) | Cod sursa (job #2082863) | Cod sursa (job #652855) | Cod sursa (job #2251042) | Cod sursa (job #195099)
Cod sursa(job #195099)
var f,g:text;
l1,l,c,c1:array[1..16] of longint;
v:array[1..16,1..16] of longint;
n,m,i,x,xx,j,s,max,q:longint;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
read(f,n,m);
for i:=1 to n do
for j:=1 to m do begin
read(f,v[i,j]);
l[i]:=l[i]+v[i,j];
c[j]:=c[j]+v[i,j];
end;
max:=0;
for i:=1 to n do
max:=max+l[i];
for i:=1 to m do
max:=max+c[i];
max:=max div 2;
for x:=1 to 1 shl (m+n-1) do begin
xx:=x;
s:=0;
for i:=1 to m+n do begin
if xx mod 2=1 then begin
if i<=n then begin
l1[i]:=l1[i]*-1;
for j:=1 to m do
inc(c1[j],2*v[i,j]);
end;
if i>n then begin
c1[i]:=c1[i]*-1;
for j:=1 to m do
inc(l1[j],2*v[j,i]);
end;
end;
xx:=xx div 2;
end;
for j:=1 to n do begin
s:=s+l1[j];
l1[j]:=l[j];
end;
for j:=1 to m do begin
s:=s+c1[j];
c1[j]:=c[j];
end;
s:=s div 2;
if s>max then max:=s;
end;
writeln(g,max);
close(f);
close(g);
end.