Cod sursa(job #2183)

Utilizator alex_dincaDinca Alexandru-Nicolae - UPB alex_dinca Data 16 decembrie 2006 11:15:22
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.61 kb
var n,m,i,j,k,s,t,max:longint;f:text;
    a:array[1..16,1..16] of longint;
begin
assign(f,'flip.in');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;
close(f);
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 s>max then max:=s;
    end;
assign(f,'flip.out');rewrite(f);
writeln(f,max);
close(f);
end.