Cod sursa(job #589464)

Utilizator ScriamTertiuc Afanasie Scriam Data 12 mai 2011 16:07:27
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.73 kb
Program p1;
var  a : array[1..100,1..100] of longint;
     n,m,max : longint;




Procedure citire;
var fin : text;
    i,j : integer;
begin
assign(fin,'flip.in');
reset(fin);
readln(fin,n,m);
for i:=1 to n do
 for j:=1 to m do
 read(fin,a[i,j]);
close(fin);
end;



Procedure calc;
var s,i,j,t,k : longint;
    fout : text;
begin
for i:=1 to (1 shl m) do
  begin
  s:=0;
  for k:=1 to n do
      begin
      t:=0;
      for j:=1 to m do
          if i and (1 shl (j-1))>0 then t:=t-a[k,j] else
          t:=t+a[k,j];
      if t<-t then s:=s-t else s:=s+t;
      end;
  if s>max then max:=s;
  end;
assign(fout,'flip.out');
rewrite(fout);
writeln(fout,max);
close(fout);
end;

begin
citire;
calc;
end.