Pagini recente » Cod sursa (job #2580380) | Cod sursa (job #2930384) | Cod sursa (job #704381) | Borderou de evaluare (job #1138963) | Cod sursa (job #18687)
Cod sursa(job #18687)
var n,sol:byte;
a:array[1..600] of byte;
c:array[1..256] of byte;
m:set of byte;
procedure citire;
var i:integer;
begin
assign(input,'culori.in');
reset(input);
readln(n);
for i:=1 to 2*n-1 do
read(a[i]);
close(input);
end;
procedure prel(vf,nr,t:integer);
var i:integer;
begin
if nr=n then
inc(sol)
else
begin
c[vf]:=a[nr];
for i:=1 to n do
if not (i in m ) then
if (c[i]=0) or ((nr<n) and (c[i]=a[nr+1])) then
begin
m:=m+[t];
prel(i,nr+1,vf);
m:=m-[t];
end
end;
end;
begin
assign(output,'culori.out');
rewrite(output);
citire;
prel(1,1,0);
writeln(sol);
close(output);
end.