login
A338738
Number of permutations p of [n] such that |p(i) - p(i-1)| <= |p(i+1) - p(i)|.
2
1, 1, 2, 4, 6, 8, 10, 14, 20, 24, 32, 40, 48, 70, 94, 126, 162, 228, 292, 386, 528, 710, 956, 1298, 1730, 2342, 3178, 4192, 5684, 7720, 10340, 14002, 18816, 25372, 34054
OFFSET
0,3
EXAMPLE
a(4) = 6: 1234, 2314, 2341, 3214, 3241, 4321.
MAPLE
b:= proc(s, x, y) option remember; `if`(s={}, 1, add(
`if`(x=0 or y=0 or abs(x-y)<=abs(y-j),
b(s minus {j}, y, j), 0), j=s))
end:
a:= n-> b({$1..n}, 0$2):
seq(a(n), n=0..16);
MATHEMATICA
b[s_, x_, y_] := b[s, x, y] = If[s == {}, 1, Sum[If[x == 0 || y == 0 || Abs[x - y] <= Abs[y - j], b[s ~Complement~ {j}, y, j], 0], {j, s}]];
a[n_] := b[Range[n], 0, 0];
Table[Print[n, " ", a[n]]; a[n], {n, 0, 20}] (* Jean-François Alcover, Sep 08 2021, after Alois P. Heinz *)
CROSSREFS
Cf. A338614.
Sequence in context: A122642 A305703 A177867 * A345986 A226809 A161562
KEYWORD
nonn,more
AUTHOR
Alois P. Heinz, Nov 05 2020
EXTENSIONS
a(27)-a(34) from Bert Dobbelaere, Nov 15 2020
STATUS
approved