Cod sursa(job #391288)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 5 februarie 2010 13:45:28
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.68 kb
program flip;
var a:array[1..16,1..16]of longint;
y:array[1..16]of -1..1;
n,m,i,j:byte;
s:longint;

procedure caut;
var ss,aux:longint;
i,j:byte;
begin
ss:=0;
for i:=1 to n do begin
    aux:=0;
    for j:=1 to m do aux:=aux+(y[j]*a[i,j]);
    ss:=ss+abs(aux);
    end;
if ss>s then s:=ss;
end;




procedure go(k:byte);
begin
y[k]:=1;
if k=m then caut
       else go(k+1);
y[k]:=-1;
if k=m then caut
       else go(k+1);
end;


begin
assign(input,'flip.in'); reset(input);
read(n,m);
for i:=1 to n do
    for j:=1 to m do read(a[i,j]);
close(input);
s:=(-1)*maxlongint;
go(1);
assign(output,'flip.out'); rewrite(output);
write(s);
close(output);
end.