Cod sursa(job #337515)

Utilizator sapiensCernov Vladimir sapiens Data 3 august 2009 21:28:23
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.87 kb
Program flip;
 var f,g:text; a:array[1..16,1..16]of longint;
     b:array[1..16]of -1..1;
     i,j,m,n:byte; s,smax:longint;
 function maxim (x,y:longint):longint;
  begin
   if x>y then exit (x) else exit (y);
  end;
 function sum:longint;
  var x,y:byte; z:longint;
  begin
   s:=0;
   for x:=1 to n do begin
     z:=0;
     for y:=1 to m do z:=z+a[x,y]*b[y];
     s:=s+abs (z);
   end;
  end;
 procedure calcul (x:byte);
  begin
   if x=n then smax:=maxim (sum,smax) else begin
     b[x+1]:=1;
     calcul (x+1);
     b[x+1]:=-1;
     calcul (x+1);
   end;
  end;
 begin
  assign (f,'flip.in'); reset (f);
  assign (g,'flip.out'); rewrite (g);
  readln (f,n,m);
  for i:=1 to n do begin
    for j:=1 to m do read (f,a[i,j]);
    readln (f);
  end;
  b[1]:=1;
  smax:=-maxlongint-1;
  calcul (1);
  writeln (g,smax);
  close (f); close (g);
 end.