Cod sursa(job #333889)

Utilizator sapiensCernov Vladimir sapiens Data 24 iulie 2009 14:34:22
Problema Jocul Flip Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.17 kb
Program flip;
 const nmax = 16;
       vmax = 1000000;
 var f,g:text; a:array[1..nmax,1..nmax]of -vmax..vmax;
     b,c:array[0..nmax]of -1..1;
     m,n:byte; sum,smax:longint;
 procedure initiere;
  var x,y:byte;
  begin
   assign (f,'flip.in'); reset (f);
   assign (g,'flip.out'); rewrite (g);
   readln (f,n,m);
   for x:=1 to n do begin
     for y:=1 to m do read (f,a[x,y]);
     readln (f);
   end;
   for x:=0 to n do b[x]:=1;
   for x:=0 to m do c[x]:=1;
  end;
 procedure calcul;
  var x,y:byte;
  begin
   smax:=0;
   for x:=1 to n do for y:=1 to m do smax:=smax+a[x,y];
   while b[0]=1 do begin
     x:=n;
     while b[x]=-1 do begin
       b[x]:=1;
       x:=x-1;
     end;
     b[x]:=-1;
     c[0]:=1;
     while c[0]=1 do begin
       y:=m;
       while c[y]=-1 do begin
         c[y]:=1;
         y:=y-1;
       end;
       c[y]:=-1;
       sum:=0;
       for x:=1 to n do
         for y:=1 to m do
           sum:=sum+a[x,y]*b[x]*c[y];
       if sum>smax then smax:=sum;
     end;
   end;
  end;
 procedure incheiere;
  begin
   writeln (g,smax);
   close (f); close (g);
  end;
 begin
  initiere;
  calcul;
  incheiere;
 end.