Cod sursa(job #385167)

Utilizator smotruSergiu Falcusan smotru Data 22 ianuarie 2010 10:40:38
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.78 kb
type rac=array [1..16,1..16] of longint;
     act=array [1..16] of -1..1;
var n,m,i,j:longint;
    smax:longint;
    a:rac;
    sol:act;
    f:text;
procedure evaluare;
var i,j,s,sc:longint;
begin
s:=0;
for i:=1 to m do
    begin
    sc:=a[1,i];
    for j:=2 to n do
        sc:=sc+sol[j]*a[j,i];
    s:=s+abs(sc);
    end;
if smax<s then smax:=s;
end;

procedure back(p:integer);
begin
sol[p]:=1;
if p=n then evaluare
       else back(p+1);
sol[p]:=-1;
if p=n then evaluare
       else back(p+1);
end;



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);
smax:=0;
back(1);
assign(f,'flip.out');rewrite(f);
write(f,smax);
close(f);
end.