Pagini recente » Cod sursa (job #2930615) | Cod sursa (job #3159267) | Cod sursa (job #655680) | Cod sursa (job #191020) | Cod sursa (job #306254)
Cod sursa(job #306254)
var n,m:byte; a:array [1..17,1..17] of longint;
b:array [1..17] of boolean;
max:longint;
procedure citeste;
var f:text;
i,j:byte;
begin
assign(f,'flip.in');
reset(f);
readln(f,n,m);
for i:=1 to n do for j:=1 to m do read(f,a[i,j]);
close(f);
end;
procedure urmatorul;
var i:byte;
begin
i:=1;
while b[i] do begin
b[i]:=false;
i:=i+1;
end;
b[i]:=true;
end;
procedure verif;
var i,j:byte;
s,t:longint;
begin
t:=0;
for i:=1 to n do begin
s:=0;
for j:=1 to m do if b[j] then s:=s+a[i,j]
else s:=s-a[i,j];
if s<0 then t:=t-s
else t:=t+s;
end;
if t>max then max:=t;
end;
procedure calc;
var x,i:longint;
begin
x:=1;
for i:=1 to 17 do b[i]:=false;
for i:=1 to m do x:=x*2;
for i:=1 to x do begin
verif;
urmatorul;
end;
end;
procedure afiseaza;
var f:text;
begin
assign(f,'flip.out');
rewrite(f);
write(f,max);
close(f);
end;
begin
citeste;
calc;
afiseaza;
end.