%I #16 May 30 2019 09:28:10
%S 1,1,3,7,19,48,131,348,954,2607,7212,19995,55816,156246,439267,
%T 1238397,3502004,9927260,28208628,80322048,229161413,654966245,
%U 1875074366,5376298225,15437286706,44385247519,127776425727,368276055467,1062618076382,3069264747076
%N Number of multisets of nonempty words with a total of n letters over ternary alphabet such that within each prefix of a word every letter of the alphabet is at least as frequent as the subsequent alphabet letter.
%H Alois P. Heinz, <a href="/A293733/b293733.txt">Table of n, a(n) for n = 0..1000</a>
%F G.f.: Product_{j>=1} 1/(1-x^j)^A001006(j).
%F a(n) ~ c * 3^n / n^(3/2), where c = 11.84175157992103588081767200532703865225243959779980786519467770732598276486... - _Vaclav Kotesovec_, May 30 2019
%p g:= proc(n) option remember; `if`(n<2, 1,
%p g(n-1)+add(g(k)*g(n-k-2), k=0..n-2))
%p end:
%p a:= proc(n) option remember; `if`(n=0, 1, add(add(g(d)
%p *d, d=numtheory[divisors](j))*a(n-j), j=1..n)/n)
%p end:
%p seq(a(n), n=0..35);
%t g[n_] := g[n] = If[n<2, 1, g[n-1] + Sum[g[k]*g[n-k-2], {k, 0, n-2}]];
%t a[n_] := a[n] = If[n==0, 1, Sum[Sum[g[d]*d, {d, Divisors[j]}]*a[n-j], {j, 1, n}]/n];
%t Table[a[n], {n, 0, 35}] (* _Jean-François Alcover_, May 30 2019, after _Alois P. Heinz_ *)
%o (Python)
%o from sympy.core.cache import cacheit
%o from sympy import divisors
%o @cacheit
%o def g(n): return 1 if n<2 else g(n - 1) + sum([g(k)*g(n - k - 2) for k in range(n - 1)])
%o @cacheit
%o def a(n): return 1 if n==0 else sum([sum([g(d)*d for d in divisors(j)])*a(n - j) for j in range(1, n + 1)])//n
%o print(map(a, range(36))) # _Indranil Ghosh_, Oct 15 2017
%Y Column k=3 of A293108.
%Y Cf. A001006.
%K nonn
%O 0,3
%A _Alois P. Heinz_, Oct 15 2017
|