OFFSET
0,4
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..400
Wikipedia, Counting lattice paths
FORMULA
a(2n) = A303287(2n).
EXAMPLE
a(0) = 1: the empty permutation.
a(1) = 1: 1.
a(2) = 1: 21.
a(3) = 4: 132, 213, 231, 312.
a(4) = 8: 1432, 2143, 2431, 3142, 3241, 3421, 4132, 4231.
MAPLE
b:= proc(u, o, t) option remember; `if`(u+o=0, 1,
`if`(t>0, add(b(u-j, o+j-1, t-1), j=1..u), 0)+
`if`(o+u>t, add(b(u+j-1, o-j, t+1), j=1..o), 0))
end:
a:= n-> b(0, n, 0):
seq(a(n), n=0..25);
MATHEMATICA
b[u_, o_, t_] := b[u, o, t] = If[u + o == 0, 1, If[t > 0, Sum[b[u - j, o + j - 1, t - 1], {j, 1, u}], 0] + If[o + u > t, Sum[b[u + j - 1, o - j, t + 1], {j, 1, o}], 0]];
a[n_] := b[0, n, 0];
Table[a[n], {n, 0, 25}] (* Jean-François Alcover, May 25 2018, translated from Maple *)
PROG
(PARI) b(u, o, t) = if(u+o==0, 1, if(t > 0, sum(j=1, u, b(u-j, o+j-1, t-1)), 0) + if(o+u > t, sum(j=1, o, b(u+j-1, o-j, t+1)), 0))
a(n) = b(0, n, 0) \\ Felix Fröhlich, May 25 2018, adapted from Mathematica
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Apr 20 2018
STATUS
approved