Pagini recente » Cod sursa (job #1655572) | Cod sursa (job #2042461) | Cod sursa (job #1686276) | Cod sursa (job #751759) | Cod sursa (job #27988)
Cod sursa(job #27988)
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 sor[x]<>sor[y] then summa:=0 else
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,summa(1,n));
close(T);
end.