Pagini recente » Cod sursa (job #1517285) | Cod sursa (job #868258) | Cod sursa (job #2615946) | Cod sursa (job #2410972) | Cod sursa (job #1453987)
type tablou=array [0..17]of byte;
matrice=array [1..16,1..16]of longint;
var a:matrice;
t1,t2:tablou;
i,j,k,m,n,max,p,q,s,x,y:longint;
f,g:text;
begin
assign(f,'flip.in');
assign(g,'flip.out');
reset(f);
rewrite(g);
read(f,n,m);
for i:=1 to n do
for j:=1 to m do
read(f,a[i,j]);
p:=1;
q:=1;
for i:=1 to n do
p:=p*2;
for j:=1 to m do
q:=q*2;
i:=1;
max:=-maxint;
while i<=p do
begin
j:=1;
while j<=q do
begin
s:=0;
for x:=1 to n do
for y:=1 to m do
if ((t1[x]=0)or(t2[y]=0))and((t1[x]=1)or(t2[y]=1)) then s:=s-a[x,y]
else s:=s+a[x,y];
if s>max then max:=s;
t2[m]:=t2[m]+1;
y:=m;
repeat
if t2[y]=2 then begin
t2[y]:=0;
t2[y-1]:=t2[y-1]+1;
end;
y:=y-1;
until t2[y]<2;
j:=j+1;
end;
t1[n]:=t1[n]+1;
y:=n;
repeat
if t1[y]=2 then begin
t1[y]:=0;
t1[y-1]:=t1[y-1]+1;
end;
y:=y-1;
until t1[y]<2;
i:=i+1;
for x:=0 to m do
t2[x]:=0;
end;
write(g,max);
close(f);
close(g);
end.