Pagini recente » Cod sursa (job #615059) | Cod sursa (job #1653448) | Cod sursa (job #2009143) | Cod sursa (job #3131760) | Cod sursa (job #337515)
Cod sursa(job #337515)
Program flip;
var f,g:text; a:array[1..16,1..16]of longint;
b:array[1..16]of -1..1;
i,j,m,n:byte; s,smax:longint;
function maxim (x,y:longint):longint;
begin
if x>y then exit (x) else exit (y);
end;
function sum:longint;
var x,y:byte; z:longint;
begin
s:=0;
for x:=1 to n do begin
z:=0;
for y:=1 to m do z:=z+a[x,y]*b[y];
s:=s+abs (z);
end;
end;
procedure calcul (x:byte);
begin
if x=n then smax:=maxim (sum,smax) else begin
b[x+1]:=1;
calcul (x+1);
b[x+1]:=-1;
calcul (x+1);
end;
end;
begin
assign (f,'flip.in'); reset (f);
assign (g,'flip.out'); rewrite (g);
readln (f,n,m);
for i:=1 to n do begin
for j:=1 to m do read (f,a[i,j]);
readln (f);
end;
b[1]:=1;
smax:=-maxlongint-1;
calcul (1);
writeln (g,smax);
close (f); close (g);
end.