# Cod sursa(job #13312)

Utilizator Data 6 februarie 2007 09:46:52 Jocul Flip 60 fpc done Arhiva de probleme 2.2 kb
``````{\$IFDEF NORMAL}
{\$I-,Q-,R-,S-}
{\$ENDIF NORMAL}
{\$IFDEF DEBUG}
{\$I+,Q+,R+,S-}
{\$ENDIF DEBUG}
{\$IFDEF RELEASE}
{\$I-,Q-,R-,S-}
{\$ENDIF RELEASE}

var fi,fo:text;
n,m,i,j:longint;
col,int:array[1..20] of longint;
v,aux:array[1..20,1..20] of longint;
max,peak:longword;
l1:longint;
a:array[0..35000,1..16] of integer;

procedure sumcol(x:longint);
var sum,j:longint;
begin
sum:=0;
for i:=1 to n do
sum:=sum+v[i,x];
col[x]:=sum;
end;

procedure invlin(x:longint);
var j:longint;
begin
for j:=1 to m do
begin
col[j]:=col[j]-2*aux[x,j];
aux[x,j]:=-aux[x,j];
end;
end;

procedure gosolve;
var i,j,k,l:longint;
begin
for i:=1 to m do
sumcol(i);
int:=col;
for i:=0 to l1 do
begin
aux:=v;
col:=int;
for j:=1 to n do
if a[i,j]=1 then invlin(j);
peak:=0;
for j:=1 to m do
if col[j]>0 then peak:=peak+col[j]
else peak:=peak+abs(col[j]);
if peak>max then max:=peak;
// writeln(fo,peak);
end;
end;

procedure b2I(x:longint);
var int,i,j:longint;
begin
for i:=0 to x do
begin
int:=i;
j:=1;
while int<>0 do
begin
a[i,j]:=int mod 2;
int:=int div 2;
inc(j);
end;
end;

end;

begin
peak:=maxlongint;
assign(fi,'flip.in'); reset(fi);
assign(fo,'flip.out'); rewrite(fo);
for i:=1 to n do
for j:=1 to m do
case n of
1: l1:=1;
2: l1:=3;
3: l1:=7;
4: l1:=15;
5: l1:=31;
6: l1:=63;
7: l1:=127;
8: l1:=255;
9: l1:=511;
10: l1:=1023;
11: l1:=2047;
12: l1:=4095;
13: l1:=8191;
14: l1:=16383;
15: l1:=32767;
end;
b2I(l1);

{   for i:=0 to l1 do
begin
for j:=1 to n do
write(fo,a[i,j],' ');
writeln(fo);
end;
for i:=0 to l2 do
begin
for j:=1 to m do
write(fo,b[i,j],' ');
writeln(fo);
end;}
gosolve;
write(fo,max);
close(fi);
close(fo);
end.
``````