Pagini recente » Cod sursa (job #420846) | Cod sursa (job #2841943) | Cod sursa (job #202435) | Cod sursa (job #2850543) | Cod sursa (job #114469)
Cod sursa(job #114469)
program infoarena_flip;
var i,j,k,k1,k2,m,n,x,y,s,smax,i2,j2,k3:longint;
a:array[1..16,1..16] of longint;
b1,b2:array[1..16] of byte;
begin
assign(input,'flip.in');
reset(input);
read(n);readln(m);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
close(input);
smax:=0;
for i:=1 to n do
for j:=1 to m do
begin
smax:=smax+a[i,j];
end;
i:=2;
i:=i shl n-2;
i:=i-1;
j:=2;
j:=j shl m-2;
j:=j-1;
for k1:=1 to i do
for k2:=1 to j do
begin
k:=k1;
x:=1;
while (k<>0)and(k<>1) do
begin
b1[x]:=k mod 2;
k:=k div 2;
x:=x+1;
end;
b1[x]:=k;
k:=0;
k:=k2;
y:=1;
while (k<>0)and(k<>1) do
begin
b2[y]:=k mod 2;
k:=k div 2;
y:=y+1;
end;
b2[x]:=k;
k:=0;
s:=0;
for i2:=1 to n do
for j2:=1 to m do
begin
if b1[i2]=1 then k3:=-1
else k3:=1;
if b2[j2]=1 then k3:=k3*(-1);
s:=s+a[i2,j2]*k3;
end;
if s>smax then smax:=s;
end;
assign(output,'flip.out');
rewrite(output);
writeln(smax);
close(output);
end.