Cod sursa(job #324312)

Utilizator cristian3991Udroiu Constantin Cristian cristian3991 Data 15 iunie 2009 16:40:30
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.08 kb
 var f,g:text;  
     a:array[1..17,1..17] of longint;  
     x:array[0..17] of integer;  
     i,n,m,j,s,max,ss:longint;  
 begin  
      assign(f,'flip.in');reset(f);  
      assign(g,'flip.out');rewrite(g);  
      read(f,n,m);  
      for i:=1 to n do  
          for j:=1 to m do  
              begin  
              read(f,a[i,j]);  
              max:=max+a[i,j];  
              end;  
      while x[0]=0 do  
            begin  
                 i:=n;  
                 while x[i]=1 do begin x[i]:=0;i:=i-1; end;  
                 x[i]:=1;  
                 s:=0;  
                 for j:=1 to m do  
                     begin  
                          ss:=0;  
                          for i:=1 to n do  
                              if x[i]=1 then ss:=ss-a[i,j]  
                                        else ss:=ss+a[i,j];  
                          if ss<0 then ss:=-ss;  
                          s:=s+ss;  
                     end;  
                 if max<s then max:=s;  
            end;  
      writeln(g,max);  
 close(f);  
 close(g);  
 end