Pagini recente » Cod sursa (job #2952034) | Cod sursa (job #635519) | Cod sursa (job #2004634) | ONIS 2014, Clasament | Cod sursa (job #27966)
Cod sursa(job #27966)
var sor:array[1..256] of byte;
a:array[1..256,1..256] of longint;
N,i,j:integer;
t:text;
function summa(x,y:integer):longint;
var k:integer;
osz:longint;
begin
if x=y then summa:=1
else if x+1=y then summa:=0
else if x+2=y then summa:=1
else
begin
osz:=0;
for k:=x+1 to y-1 do
begin
osz:=osz+(summa(x+1,k)*summa(k+1,y));
end;
summa:=osz;
end;
end;
begin
assign(t,'culori.in');
reset(T);
read(t,N);
n:=2*n-1;
for i:=1 to n do read(t,sor[i]);
for i:=1 to n do for j:=1 to n do a[i,j]:=0;
for i:=1 to n do a[i,i]:=1;
close(T);
for i:=1 to n do
for j:=i+1 to n do
if (i+j) mod 2=0 then
if sor[i]=sor[j] then
begin
a[i,j]:=summa(i,j);
end;
assign(t,'culori.out');
rewrite(T);
writeln(t,a[1,n]);
close(T);
end.