Pagini recente » Cod sursa (job #164285) | Cod sursa (job #1852661) | Cod sursa (job #798794) | Cod sursa (job #1979988) | Cod sursa (job #743768)
Cod sursa(job #743768)
program joc;
type vector=array[1..16,1..16] of longint;
subm=array[0..16] of shortint;
var a:vector;
v:subm;
n,m,i,j:byte;
smax:longint;
procedure calcul;
var s:longint;
aux:array[1..16] of longint;
i,j:byte;
begin
s:=0;
for i:=1 to m do aux[i]:=0;
for i:=1 to n do
for j:=1 to m do aux[j]:=aux[j]+a[i,j]*v[i];
for i:=1 to m do
if aux[i]<0 then s:=s-aux[i]
else s:=s+aux[i];
if s>smax then smax:=s;
end;
procedure back(k:byte);
begin
if k=n+1 then calcul
else begin
v[k]:=-1;
back(k+1);
v[k]:=1;
back(k+1)
end;
end;
begin
assign(input,'flip.in'); reset(input);
assign(output,'flip.out'); rewrite(output);
readln(n,m);
for i:=1 to n do begin
for j:=1 to m do begin
read(a[i,j]);
smax:=smax+a[i,j];
end;
readln;
end;
close(input);
back(1);
write(smax);
close(output);
end.