Pagini recente » Cod sursa (job #3263304) | Cod sursa (job #3153644) | Cod sursa (job #3153282) | Cod sursa (job #3215552) | Cod sursa (job #1996477)
Program Flip;
type max = 1..16;
tab = array[max,max] of -1000000..1000000;
var n,m,i,j:max;
fl:tab;
stack: array[max] of 0..1;
a,s:longint;
f,g:text;
function Solutie:longint;
var i,j:max;
s:longint;
begin
s:=0;
for i:=1 to n do begin
for j:=1 to m do
if stack[j] = 0 then
s:=s+fl[i,j]
else
s:=s-fl[i,j];
end;
end;
procedure backtrack(k:max);
var x: longint;
begin
if k > m then begin
x:= solutie;
if x > s then s:= x;
exit;
end;
stack[k]:=0;
backtrack(k+1);
stack[k]:=1;
backtrack(k+1);
end;
begin
assign(f,'flip.in');assign(g,'flip.out');
reset(f);rewrite(g);
readln(f,n,m);
for i:=1 to n do begin
for j:=1 to m do
read(f,fl[i,j]);
readln(f);
end;
Backtrack(1);
writeln(g,s);
close(f);close(g);
end.