Pagini recente » Cod sursa (job #2083573) | Cod sursa (job #1605884) | Cod sursa (job #2610862) | Cod sursa (job #331086) | Cod sursa (job #172165)
Cod sursa(job #172165)
{ http://infoarena.ro/problema/flip }
type matrice = array[1..16,1..16] of longint;
stiva = array[1..16] of shortint;
var
f, g : text;
a : matrice;
st : stiva;
i, j, n, m : byte;
smax : longint;
procedure suma;
var i, j : byte;
s, scol : longint;
begin
s := 0;
for i := 1 to n do
begin
scol := 0;
for j := 1 to m do
scol := scol + st[j] * a[i,j];
if scol < 0 then s := s - scol
else s := s + scol;
end;
if s > smax then smax := s;
end;
procedure back(i : integer);
begin
if i = m then suma
else begin
st[i] := 1;
back(i + 1);
st[i] := -1;
back(i + 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
for j := 1 to m do
read(f, a[i,j]);
smax := -maxlongint;
back(1);
writeln(g, smax);
close(f); close(g);
END.