Cod sursa(job #150680)

Utilizator asafteirobertAsaftei Robert asafteirobert Data 7 martie 2008 11:38:07
Problema Jocul Flip Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.88 kb
program infoarena_flip;
var i,j,k,k1,k2,m,n,s,smax,i1,j1,x1,x2:longint;
    a:array[1..16,1..16] of longint;

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; }


i1:=1;
i1:=i1 shl n;
i1:=i1-1;
j1:=1;
j1:=j1 shl m;
j1:=j1-1;

for k1:=1 to i1 do
 for k2:=1 to j1 do
  begin
   s:=0;

   for i:=1 to n do
    begin
      if k1 and (1 shl (i-1))>0 then x1:=-1
                                else x1:=1;
    for j:=1 to m do
     begin
      if k2 and (1 shl (j-1))>0 then x2:=-1
                                else x2:=1;
      s:=s+a[i,j]*x1*x2;
     end;
     end;
   if s>smax then smax:=s;
  end;



assign(output,'flip.out');
rewrite(output);
writeln(smax);
close(output);

end.