Pagini recente » Cod sursa (job #2908763) | Cod sursa (job #161993) | Cod sursa (job #3209576) | Cod sursa (job #3214381) | Cod sursa (job #303193)
Cod sursa(job #303193)
var f,g:text;
v:array[1..16,1..16] of longint;
sum:array[1..16] of longint;
ok:array[1..16] of boolean;
i,j,n,m,s,k,max:longint;
ll:boolean;
procedure back(poz:integer);
begin
if poz<=k then begin
ok[poz]:=true;
back(poz+1);
ok[poz]:=false;
back(poz+1);
end
else begin
{if ll then begin}
fillchar(sum,sizeof(sum),0);
for i:=1 to n do
for j:=1 to m do
if ok[i] then sum[j]:=sum[j]-v[i,j]
else sum[j]:=sum[j]+v[i,j];
s:=0;
for i:=1 to m do
s:=s+abs(sum[i]);
if max<s then max:=s;
{end
else begin
fillchar(sum,sizeof(sum),0);
for i:=1 to m do
for j:=1 to n do
if ok[i] then sum[j]:=sum[j]-v[j,i]
else sum[j]:=sum[j]+v[j,i];
s:=0;
for i:=1 to n do
s:=s+abs(sum[i]);
if max<s then max:=s;
end;}
end;
end;
begin
assign (f,'flip.in');reset(f);
assign (g,'flip.out');rewrite (g);
readln (f,n,m);
if n<m then begin
k:=n;
ll:=true;
end
else begin
k:=m;
ll:=false;
end;
for i:=1 to n do
for j:=1 to m do
read(f,v[i,j]);
max:=0;
back(1);
writeln (g,max);
close(f);close(g);
end.