Cod sursa(job #956208)

Utilizator DjokValeriu Motroi Djok Data 2 iunie 2013 15:28:21
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.69 kb
var a: array[0..100,0..100] of longint;
    max, n, m, s, t, i, j, k:longint;
    fi,fo:text;
begin
assign(fi,'flip.in');
assign(fo,'flip.out');
rewrite(fo);
reset(fi);
readln(fi,n,m);
  for i:=1 to n do
   for j:=1 to m do
    read(fi,a[i,j]);
       for i:=1 to (1 shl m)do begin s:=0;
        for k:=1 to n do begin
         t:=0;
          for j:=1 to m do
            if i and (1 shl(j-1))>0 then t:=t-a[k,j]
                                    else t:=t+a[k,j];
             if t<-t then s:=s-t
                     else s:=s+t;
                          end;
              if s>max then max:=s;
                 end;
      writeln(fo,max);
      close(fi);
      close(fo);
end.