Cod sursa(job #1169915)

Utilizator Mihai_ChihaiMihai Chihai Mihai_Chihai Data 12 aprilie 2014 13:08:16
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.68 kb
program flip;
  var a:array[1..16,1..16] of longint;
     n,m,i,j,k,sum,c,bestsum:longint;
  begin
   assign(input,'flip.in');
   reset(input);
   assign(output,'flip.out');
   rewrite(output);
   readln(n,m);
   for i:=1 to n do
    for j:=1 to m do read(a[i,j]);
   for i:=0 to 1 shl n do
    begin
      sum:=0;
      for j:=1 to m do
        begin
          c:=0;     {c- suma pe coloana}
        for k:=1 to n do
          if i and (1 shl k)=0 then c:=c+a[k,j]
                                else c:=c-a[k,j];
         if c<0 then c:=-c;;
         sum:=sum+c;
        end;
      if sum>bestsum then bestsum:=sum;
    end;
   write(bestsum);
   close(output);
   end.