Cod sursa(job #302992)

Utilizator AndreiDumaAndrei Duma AndreiDuma Data 9 aprilie 2009 14:15:50
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.81 kb
var a:array[1..16,1..16] of longint;
    sol:array[1..16] of integer;
    n,m,i,j,s,total,max:longint;

    f:text;

procedure citire;
var f:text;
begin
	assign(f,'flip.in');reset(f);
	readln(f,m,n);
	for i:=1 to m do
	begin
		for j:=1 to n do read(f,a[i,j]);
		readln(f);
	end;
        close(f);
end;

procedure calculeaza;
var i,j:integer;
begin
	total:=0;
	for i:=1 to m do
	begin
		s:=0;
		for j:=1 to n do s:=s+a[i,j]*sol[j];
		if s<0 then s:=-s;
		total:=total+s;
	end;

	if total>max then max:=total;
end;

procedure back (i:integer);
begin
	if i=n+1 then calculeaza
	         else
			 begin
			 sol[i]:=-1;
			 back(i+1);

			 sol[i]:=1;
			 back(i+1);
			 end;
end;

begin
	citire;

	back(1);
	
	assign(f,'flip.out');rewrite(f);
	writeln(f,max);
	close(f);
end.