Cod sursa(job #318287)

Utilizator adella_stanciuStanciu Adela adella_stanciu Data 27 mai 2009 21:53:32
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.89 kb
var f : text;
    n, m, i, j : byte;
    mat : array[1..16,1..16] of longint;
    x : array[1..16] of longint;
    s, max : longint;

procedure rez;
var s1 : longint;
begin
     s := 0;
     for i := 1 to n do begin
          s1 := 0;
          for j := 1 to m do
               s1 := s1 + mat[i,j] * x[j];
          if s1 > 0 then s := s + s1
          else s := s - s1;
     end;
     if s > max then max := s;
end;


procedure back(k : integer);
begin
     if k = m+ 1 then begin
          rez;
          exit;
     end;
     x[k] := 1;
     back(k + 1);
     x[k] := -1;
     back(k + 1);

end;


begin
     assign(f,'flip.in'); reset(f);
     readln(f,n,m);
     s := 0;
     for i := 1 to n do
         for j := 1 to m do
          read(f,mat[i,j]);
     close(f);
     back(1);
     assign(f,'flip.out'); rewrite(f);
     writeln(f,max);
     close(f);
end.