Pagini recente » Cod sursa (job #2651980) | Cod sursa (job #1011026) | Borderou de evaluare (job #261605) | Cod sursa (job #3182424) | Cod sursa (job #461403)
Cod sursa(job #461403)
program flip;
type ma=array [1..16,1..16] of longint;
ta=array [1..16] of -1..1;
var n,m,i,j:longint;
smax:longint;
a:ma;
sol:ta;
fin,fout:text;
procedure evaluare;
var i,j,s,sc:longint;
begin
s:=0;
for i:=1 to m do
begin
sc:=a[1,i];
for j:=2 to n do
sc:=sc+sol[j]*a[j,i];
s:=s+abs(sc);
end;
if smax<s then smax:=s;
end;
procedure back(p:integer);
begin
sol[p]:=1;
if p=n then
evaluare
else
back(p+1);
sol[p]:=-1;
if p=n then
evaluare
else
back(p+1);
end;
begin
assign(fin,'flip.in');reset(fin);
assign(fout,'flip.out');rewrite(fout);
readln(fin,n,m);
for i:=1 to n do
begin
for j:=1 to m do
read (fin,a[i,j]);
readln(fin);
end;
close(fin);
smax:=0;
back(1);
write(fout,smax);
close(fout);
end.