Cod sursa(job #244882)

Utilizator cheery_g1rlHaller Emanuela cheery_g1rl Data 16 ianuarie 2009 11:15:06
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.92 kb
var a:array[1..16,1..16] of longint;
    n,m,i,j,max:longint;
    st:array[1..20] of 0..1;
procedure back(k:longint);
    var t,s:longint;
    begin
      if k=m then
        begin
          s:=0;
          for i:=1 to n do
             begin
               t:=0;
               for j:=1 to m do
                 if st[j]=1 then inc(t,-a[i,j])
                    else inc(t,a[i,j]);
               if t>-t then inc(s,t)
                    else inc(s,-t);
             end;
          if s>max then max:=s;

        end
           else
             begin
                  st[k]:=0; back(k+1);
                  st[k]:=1; back(k+1);
             end;
    end;
begin
assign(input,'flip.in'); reset(input);
readln(n,m);
for i:=1 to n do
  begin
    for j:=1 to m do read(a[i,j]);
    readln;
  end;
close(input);
max:=0;
back(1);
assign(output,'flip.out'); rewrite(output);
writeln(max);
close(output);
end.