OFFSET
0,7
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..150
EXAMPLE
a(0) = 1: the empty permutation.
a(3) = 1: 123.
a(4) = 1: 1234.
a(5) = 1: 12345.
a(6) = 20: 123456, 124356, 125346, 126345, 134256, 135246, 136245, 145236, 146235, 156234, 234156, 235146, 236145, 245136, 246135, 256134, 345126, 346125, 356124, 456123.
MATHEMATICA
A[n_, k_] := A[n, k] = Module[{b}, b[u_, o_, t_] := b[u, o, t] =
If[t + o <= k, (u + o)!,
Sum[b[u + i - 1, o - i, Min[k, t] + 1], {i, 1, o}] +
If[t <= k, u*(u + o - 1)!,
Sum[b[u - i, o + i - 1, 1], {i, 1, u}]]];
Sum[b[j - 1, n - j, 1], {j, 1, n}]];
a[n_] := n! - A[n, 2];
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Aug 29 2013
STATUS
approved