Cod sursa(job #1148758)
Utilizator | Data | 21 martie 2014 08:18:41 | |
---|---|---|---|
Problema | Jocul Flip | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 2.06 kb |
program p1;
var n,m:byte;
f,g:text;
i,nr,nr1,j,k,s,u1,u,i1,i2,k1,max:longint;
a,b:array[0..20,0..20] of longint;
d,c:array[0..132] of longint;
begin
assign(f,'flip.in');reset(F);
assign(g,'flip.out');rewrite(G);
readln(f,n,m);
for i:=1 to n do begin
for j:=1 to m do begin read(f,a[i,j]); b[i,j]:=a[i,j]; max:=max+b[i,j]; end;
readln(F);
end;
for i:=1 to (1 shl n )-1 do begin
k:=0; u:=0;
while i>1 shl k do inc(K);
for j:=0 to k do
if i and (1 shl j) <>0 then begin
inc(U);
c[u]:=j+1;
end;
for j:=1 to u do
for i1:=1 to m do
b[c[j],i1]:=b[c[j],i1]*-1;
for i1:=1 to ( 1 shl m )-1 do begin
k1:=0;u1:=0;
while i1>1 shl k1 do inc(k1);
for j:=0 to k1 do
if i1 and (1 shl j)<>0 then begin
inc(u1);
d[u1]:=j+1;
end;
for j:=1 to u1 do
for i2:=1 to n do
b[i2,d[j]]:=b[i2,d[j]]*-1;
s:=0;
for i2:=1 to n do
for j:=1 to m do begin
s:=s+b[i2,j];
if s>max then begin
max:=s;
break;
end;
b[i2,j]:=a[i2,j];
end; end;
end;
writeln(g,max);
close(F);
close(G);
end.