Cod sursa(job #391263)

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

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




procedure go1(k:byte);
begin            {m,y- coloane}
y[k]:=1;
if k=m then caut
       else go1(k+1);
y[k]:=-1;
if k=m then caut
       else go1(k+1);
end;


procedure go(k:byte);
begin
x[k]:=1;                 {n,x - linii}
if k=n then go1(1)
       else go(k+1);
x[k]:=-1;
if k=n then go1(1)
       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.