Pagini recente » Cod sursa (job #515314) | Autentificare | Cod sursa (job #766669) | Cod sursa (job #3244296) | Cod sursa (job #302992)
Cod sursa(job #302992)
var a:array[1..16,1..16] of longint;
sol:array[1..16] of integer;
n,m,i,j,s,total,max:longint;
f:text;
procedure citire;
var f:text;
begin
assign(f,'flip.in');reset(f);
readln(f,m,n);
for i:=1 to m do
begin
for j:=1 to n do read(f,a[i,j]);
readln(f);
end;
close(f);
end;
procedure calculeaza;
var i,j:integer;
begin
total:=0;
for i:=1 to m do
begin
s:=0;
for j:=1 to n do s:=s+a[i,j]*sol[j];
if s<0 then s:=-s;
total:=total+s;
end;
if total>max then max:=total;
end;
procedure back (i:integer);
begin
if i=n+1 then calculeaza
else
begin
sol[i]:=-1;
back(i+1);
sol[i]:=1;
back(i+1);
end;
end;
begin
citire;
back(1);
assign(f,'flip.out');rewrite(f);
writeln(f,max);
close(f);
end.