Cod sursa(job #61564)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 19 mai 2007 20:47:41
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.83 kb
var n,m,i,j,s,t,smax,k:longint;
    a:array[1..16,1..16]of longint;
    fi,fo:text;
begin
     assign(fi,'flip.in'); reset(fi);
     assign(fo,'flip.out'); rewrite(fo);
     readln(fi,n,m);
     smax:=0;
     for i:=1 to n do
        for j:=1 to m do
            read(fi,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;
     writeln(fo,smax);
     close(fi);
     close(fo);
end.