Pagini recente » Cod sursa (job #1922366) | Cod sursa (job #1145444) | Cod sursa (job #836739) | Cod sursa (job #2969137) | Cod sursa (job #16897)
Cod sursa(job #16897)
var l,c:array[1..16]of longint;
s,smax,n,m,x,y:longint;
ll,cc:array[1..17]of 0..1;
procedure cit;
var f:text;
i,j:longint;
begin
assign(f,'flip.in');
reset(f);
readln(f,n,m);
for i:=1 to n do begin
for j:=1 to m do begin
read(f,x);
l[i]:=l[i]+x;
c[j]:=c[j]+x;
end;
readln(f);
end;
end;
procedure rez;
var i,j:longint;
begin
for i:=1 to n do smax:=smax+l[i];
while cc[m+1]=0 do begin
i:=1;
while cc[i]=1 do begin
cc[i]:=0;
i:=i+1;
end;
cc[i]:=1;
for j:=1 to n+1 do ll[j]:=0;
if cc[m+1]=0 then
while ll[n+1]=0 do begin
j:=1;
while ll[j]=1 do begin
ll[j]:=0;
j:=j+1;
end;
ll[j]:=1;
s:=0;
if ll[n+1]=0 then begin
for x:=1 to m do if cc[x]=0 then s:=s+c[x]
else s:=s-c[x];
for x:=1 to n do if ll[x]=1 then s:=s-2*l[x];
if s>smax then smax:=s;
end;
end;
end;
end;
procedure tip;
var g:text;
begin
assign(g,'flip.out');
rewrite(g);
write(g,smax);
close(g);
end;
begin
cit;
rez;
tip;
end.