Pagini recente » Cod sursa (job #335953) | Istoria paginii runda/test_concurs/clasament | Istoria paginii runda/itmarathon/clasament | Cod sursa (job #2056599) | Cod sursa (job #118001)
Cod sursa(job #118001)
var f1,f2:text;
i,j,g,n,m,h,s,max,k:longint;
a:array[0..17,0..17] of longint;
b,v:array[0..20] of longint;
procedure back;
begin
for g:=0 to 1 shl m-1 do
begin
s:=0;
k:=g;
j:=0;
while k>0 do
begin
inc(j);
v[j]:=k mod 2;
k:=k div 2;
end;
for i:=1 to m do
begin
if v[i]=1 then
h:=-1
else h:=1;
for j:=1 to n do
b[j]:=b[j]+a[j,i]*h;
end;
for i:=1 to n do
begin
s:=s+abs(b[i]);
b[i]:=0;
end;
if s>max then
max:=s;
end;
end;
begin
assign(f1,'flip.in');
reset(f1);
assign(f2,'flip.out');
rewrite(f2);
read(f1,n,m);
for i:=1 to n do
for j:=1 to m do
read(f1,a[i,j]);
back;
writeln(f2,max);
close(f1);
close(f2);
end.