Cod sursa(job #306000)

Utilizator gapdanPopescu George gapdan Data 19 aprilie 2009 12:52:24
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.48 kb
  var n,m:byte;     a:array [1..17,1..17] of longint;
  b:array [1..17] of boolean;
  max:longint;
    procedure citeste;
      var f:text;
          i,j:byte;
     begin
       assign(f,'flip.in');
       reset(f);
       readln(f,n,m);
       for i:=1 to n do for j:=1 to m do read(f,a[i,j]);
      close(f);
     end;
   procedure urmatorul;
     var i:byte;
     begin
       i:=1;
       while b[i] do begin
                      b[i]:=false;
                         i:=i+1;
                        end;
          b[i]:=true;
        end;
      procedure verif;
    var i,j:byte;
       s,t:longint;
     begin
       t:=0;
       for i:=1 to n do begin
                         s:=0;
                          for j:=1 to m do if b[j] then s:=s+a[i,j]
                                                  else s:=s-a[i,j];
                          if s<0 then t:=t-s
                                 else t:=t+s;
                      end;
      if t>max then max:=t;
   end;
   procedure calc;
     var x,i:longint;
     begin
       x:=1;
       for i:=1 to 17 do b[i]:=false;
       for i:=1 to m do x:=x*2;
       for i:=1 to x do begin
                          verif;
                          urmatorul;
                      end;
     end;
   procedure afiseaza;
     var f:text;
     begin
       assign(f,'flip.out');
       rewrite(f);
       write(f,max);
       close(f);
    end;
   begin
     citeste;
    calc;
      afiseaza;
  end.