login
Number of 1 up, 1 down, 2 up, 2 down, ... permutations of [n].
5

%I #41 Jun 16 2018 14:56:42

%S 1,1,1,2,5,9,40,111,643,2261,6176,53560,265001,976535,10699235,

%T 65839306,297528021,1096638993,16254932942,131192702293,760059358527,

%U 3527632148650,63700463354263,620906514026512,4309068955961383,23776534616426566,110660256825406666

%N Number of 1 up, 1 down, 2 up, 2 down, ... permutations of [n].

%H Alois P. Heinz, <a href="/A229551/b229551.txt">Table of n, a(n) for n = 0..300</a>

%e a(2) = 1: 12.

%e a(3) = 2: 132, 231.

%e a(4) = 5: 1324, 1423, 2314, 2413, 3412.

%e a(5) = 9: 13245, 14235, 15234, 23145, 24135, 25134, 34125, 35124, 45123.

%e a(6) = 40: 132465, 132564, ..., 561342, 562341.

%e a(7) = 111: 1324765, 1325764, ..., 6724531, 6734521.

%p b:= proc(u, o, t, k) option remember; `if`(u+o=0, 1, `if`(t>0,

%p add(b(u+j-1, o-j, `if`(t=k, [-1, k], [t+1, k])[]), j=1..o),

%p add(b(u-j, o+j-1, `if`(t=-k, [1, k+1], [t-1, k])[]), j=1..u)))

%p end:

%p a:= n-> `if`(n=0, 1, add(b(j-1, n-j, 1, 1), j=1..n)):

%p seq(a(n), n=0..35);

%t b[u_, o_, t_, k_] := b[u, o, t, k] = If[u + o == 0, 1, If[t > 0, Sum[b[u + j - 1, o - j, If[t == k, -1, t + 1], k], {j, 1, o}], Sum[b[u - j, o + j - 1, If[t == -k, 1, t - 1], If[t == -k, k + 1, k]], {j, 1, u}]]];

%t a[n_] := If[n == 0, 1, Sum[b[j - 1, n - j, 1, 1], {j, 1, n}]];

%t Table[a[n], {n, 0, 35}] (* _Jean-François Alcover_, Jun 16 2018, after _Alois P. Heinz_ *)

%Y Cf. A227941, A229066, A229892, A247550.

%K nonn,eigen

%O 0,4

%A _Alois P. Heinz_, Oct 02 2013