cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A321704 Number of words w of length n over an n-ary alphabet such that for every prefix z of w we have #(z,a_i) = 0 or #(z,a_i) >= #(z,a_j) for all j>i and #(z,a_i) counts the occurrences of the i-th letter in z.

This page as a plain text file.
%I A321704 #14 Jun 01 2022 14:44:55
%S A321704 1,1,4,18,118,895,8151,83916,977026,12602451,178880725,2766415036,
%T A321704 46314488705,834067614601,16074694453741,330017679352180,
%U A321704 7188779521480810
%N A321704 Number of words w of length n over an n-ary alphabet such that for every prefix z of w we have #(z,a_i) = 0 or #(z,a_i) >= #(z,a_j) for all j>i and #(z,a_i) counts the occurrences of the i-th letter in z.
%F A321704 a(n) = A213276(n,n).
%e A321704 a(3) = 18: aaa, aab, aac, aba, abc, aca, acb, baa, bac, bbb, bbc, bca, bcb, caa, cab, cba, cbb, ccc.
%p A321704 h:= proc(n, k, m, l) option remember;
%p A321704       `if`(n=0 and k=0, b(l), `if`(k=0 or n>0 and n<m, 0,
%p A321704        add(h(n-j, k-1, max(m, j), [j, l[]]), j=max(1, m)..n)
%p A321704           +h(n, k-1, m, [0, l[]], [])))
%p A321704     end:
%p A321704 b:= proc(l) option remember;
%p A321704       `if`({l[]} minus {0}={}, 1, add(`if`(g(l, i),
%p A321704        b(subsop(i=l[i]-1, l)), 0), i=1..nops(l)))
%p A321704     end:
%p A321704 g:= proc(l, i) local j;
%p A321704       if l[i]<1     then return false
%p A321704     elif l[i]>1     then for j from i+1 to nops(l) do
%p A321704       if l[i]<=l[j] then return false
%p A321704     elif l[j]>0     then break
%p A321704       fi od fi; true
%p A321704     end:
%p A321704 a:= n-> h(n$2, 0, []):
%p A321704 seq(a(n), n=0..10);  # _Alois P. Heinz_, Mar 29 2020
%t A321704 h[n_, k_, m_, l_] := h[n, k, m, l] = If[n == 0 && k === 0, b[l], If[k == 0 || n > 0 && n < m, 0, Sum[h[n - j, k - 1, Max[m, j], Join[{j}, l]], {j, Max[1, m], n}] + h[n, k - 1, m, Join[{0}, l]]]];
%t A321704 b[l_] := b[l] = If[Complement[l, {0}] == {}, 1, Sum[If[g[l, i], b[ReplacePart[l, i -> l[[i]] - 1]], 0], {i, 1, Length[l]}]];
%t A321704 g[l_, i_] := Module[{j}, If[l[[i]] < 1, Return[False], If[l[[i]] > 1, For[j = i + 1, j <= Length[l], j++, If[l[[i]] <= l[[j]], Return[False], If[l[[j]] > 0, Break[]]]]]]; True];
%t A321704 a[n_] := h[n, n, 0, {}];
%t A321704 Table[Print[n, " ", a[n]]; a[n], {n, 0, 15}] (* _Jean-François Alcover_, Jun 01 2022, after _Alois P. Heinz_ *)
%Y A321704 Main diagonal of A213276.
%K A321704 nonn,more
%O A321704 0,3
%A A321704 _Alois P. Heinz_, Nov 17 2018