Cod sursa(job #921062)

Utilizator DjokValeriu Motroi Djok Data 20 martie 2013 19:10:20
Problema Jocul Flip Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.98 kb
var a:array[0..200,0..200] of longint;
      bit:array[0..20] of integer;
      fi, fo:text;
      i, j, m, n:integer;
      aux, poz, s, s1, k, smax:longint;
begin
 assign(fi, 'flip.in');
 reset(fi);
 assign(fo, 'flip.out');
 rewrite(fo);
 read(fi, n,m);
  for i:=1 to n do
   for j:=1 to m do
    read(fi, a[i,j]);
    smax:=0;
     for i:=1 to (1 shl m) do begin
            aux:=i; poz:=1;
            while aux>0 do begin
               if aux mod 2=0 then bit[poz]:=1
                              else bit[poz]:=0;
                aux:=aux shr 1;
                poz:=poz+1;
                end;
                s:=0;
     for k:=1 to n do begin
      s1:=0;
       for j:=1 to m do
        if bit[j]=1 then s1:=s1+a[k,j]
                    else s1:=s1-a[k,j];
        if (s1<0) then s:=s-s1
                  else s:=s+s1;
                  end;
        if s>smax then smax:=s;
                  end;
            writeln(fo,smax);
 close(fi);
 close(fo);
end.