Pagini recente » Cod sursa (job #2401092) | Cod sursa (job #1389184) | Cod sursa (job #2550559) | Cod sursa (job #2582671) | Cod sursa (job #18206)
Cod sursa(job #18206)
const k=9901;
var f:text;
j,i,n,h:integer;
a:array[1..512,1..512] of integer;
b:array[1..512] of integer;
c:array[1..256,0..512] of integer;
sol:array[1..512] of integer;
begin
assign(f,'culori.in');
reset(f);
readln(f,n);
for i:=1 to 2*n-1 do
read(f,b[i]);
close(f);
sol[1]:=1;
for i:=1 to 2*n-1 do
begin
for j:=1 to c[b[i],0] do
begin
h:=c[b[i],j];
a[i,i-h+1]:=a[i-1,i-h-1];
sol[i]:=sol[i]+(a[i,i-h+1]*sol[h]) mod k;
end;
inc(c[b[i],0]);
c[b[i],c[b[i],0]]:=i;
a[i,1]:=1;
end;
assign(f,'culori.out');
rewrite(f);
if b[1]<>b[2*n-1] then writeln(f,0)
else writeln(f,sol[2*n-1]);
close(f);
end.