Cod sursa(job #529988)

Utilizator alexa_myparadiseAlexutzaaa alexa_myparadise Data 6 februarie 2011 17:15:14
Problema Jocul Flip Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.74 kb
program incercare;
var x:array[1..100] of integer;
    a:array[1..20,1..20] of integer;
    n,m,i,j,max:integer;
    f,g:text;
procedure suma;
var i,j:integer;
    s,s2:int64;
begin
s:=0;
for i:=1 to n do
 begin
  s2:=0;
  for j:=1 to m do begin s2:=s2+a[i,j]*x[j]; end;
  s:=s+abs(s2);
  end;
 if (max<s) then max:=s;
end;
procedure back(p:byte);
begin
 if (p>m) then
   begin
    suma;
   end
   else
    begin
     x[p]:=-1;
     back(p+1);
     x[p]:=1;
     back(p+1);
    end;
end;
begin
max:=0;
assign(f,'flip.in');
assign(g,'flip.out');
rewrite(g);
reset(f);
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;
back(1);
writeln(g,max);
close(f);
close(g);
end.