A364529 Number of compositions of 2n into n parts where differences between neighboring parts are in {-1,1}.
1, 1, 0, 2, 4, 2, 0, 6, 14, 8, 0, 25, 60, 35, 0, 114, 270, 157, 0, 528, 1242, 722, 0, 2481, 5826, 3390, 0, 11816, 27728, 16145, 0, 56841, 133316, 77660, 0, 275485, 645878, 376382, 0, 1343083, 3148000, 1835076, 0, 6579707, 15418652, 8990528, 0, 32363357, 75826214
Offset: 0
Keywords
Examples
a(0) = 1: (), the empty composition. a(1) = 1: [2]. a(3) = 2: [1,2,3], [3,2,1]. a(4) = 4: [1,2,3,2], [2,1,2,3], [2,3,2,1], [3,2,1,2]. a(5) = 2: [2,1,2,3,2], [2,3,2,1,2]. a(7) = 6: [1,2,1,2,3,2,3], [1,2,3,2,1,2,3], [1,2,3,2,3,2,1], [3,2,1,2,1,2,3], [3,2,1,2,3,2,1], [3,2,3,2,1,2,1].
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..2000
Programs
-
Maple
b:= proc(n, i, k) option remember; `if`(n<1 or i<1 or k<0 or 3/2*k>n, 0, `if`(n=i, `if`(k=0, 1, 0), add(b(n-i, i+j, k-1), j=[-1, 1]))) end: a:= n-> `if`(n=0, 1, add(b(2*n, j, n-1), j=1..2*n)): seq(a(n), n=0..48);
-
Mathematica
b[n_, i_, k_] := b[n, i, k] = If[n < 1 || i < 1 || k < 0 || 3/2*k > n, 0, If[n == i, If[k == 0, 1, 0], Sum[b[n - i, i + j, k - 1], {j, {-1, 1}}]]]; a[n_] := If[n == 0, 1, Sum[b[2*n, j, n - 1], {j, 1, 2 n}]]; Table[a[n], {n, 0, 48}] (* Jean-François Alcover, Oct 27 2023, after Alois P. Heinz *)