Pagini recente » Cod sursa (job #2323011) | Cod sursa (job #341227) | Cod sursa (job #1913387) | Cod sursa (job #78164) | Cod sursa (job #575397)
Cod sursa(job #575397)
type matrice=array[0..17,0..17]of longint;
var a,d:matrice;
i,j,n,m,nr,max,cont,s:longint;
t:text;
procedure baza(x,xx:longint; v:matrice);
var i,s1,cop,s2,s,aa:longint;
begin
cont:=0;
cop:=x;
while x<>0 do begin
inc(cont);
aa:=x mod 2;
x:=x div 2;
if aa=0 then for i:=1 to n do d[i,cont]:=-v[i,cont];
if aa=1 then for i:=1 to n do d[i,cont]:=v[i,cont];
end;
s:=0;
for i:=1 to n do begin
s1:=0;
s2:=0;
for j:=1 to m do begin
s1:=s1+d[i,j];
s2:=s2-d[i,j];
end;
if (s1<s2) then begin
for j:=1 to m do d[i,j]:=-d[i,j]; s:=s+s2 ;
end else s:=s+s1;
end;
if s>max then max:=s;
if xx<n then baza(cop,xx+1,d);
end;
begin
assign(t,'flip.in'); reset(t);
readln(t,n,m);
nr:=1;
for i:=1 to n do begin
for j:=1 to m do begin
nr:=nr*2;
read(t,a[i,j]);
end;
readln(t);
end;
nr:=nr div 2;
nr:=nr-1;
close(t);
max:=-maxlongint;
for i:=0 to nr do baza(i,1,a);
assign(t,'flip.out'); rewrite(t);
writeln(t,max);
close(t);
end.