Cod sursa(job #4180)

Utilizator charmedRoatis Carmen Maria charmed Data 31 decembrie 2006 15:15:33
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.61 kb
program flip;
var n,m,i,j,k,s,t,smax:longint;
    a:array[1..16,1..16]of longint;
    f,h:text;
begin
 assign(f,'flip.in');
 reset(f);
 readln(f,n,m);
 for i:=1 to n do
  for j:=1 to m do read(f,a[i,j]);
 for i:=0 to (1 shl m)-1 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 inc(t,-a[k,j])
                                 else inc(t,a[k,j]);
        if t<-t then inc(s,-t)
                else inc(s,t);
      end;
     if smax<s then smax:=s;
     end;
  assign(h,'flip.out');rewrite(h);
  writeln(h,smax);
end.