|
EXAMPLE
|
a(2) = 1: [1, 3]
[2, 4].
a(3) = 9:
[1, 4, 7] [1, 3, 7] [1, 2, 7] [1, 4, 6] [1, 3, 6]
[2, 5, 8] [2, 5, 8] [3, 5, 8] [2, 5, 8] [2, 5, 8]
[3, 6, 9] [4, 6, 9] [4, 6, 9] [3, 7, 9] [4, 7, 9]
.
[1, 2, 6] [1, 4, 6] [1, 3, 6] [1, 2, 6]
[3, 5, 8] [2, 5, 7] [2, 5, 7] [3, 5, 7]
[4, 7, 9] [3, 8, 9] [4, 8, 9] [4, 8, 9]. (End)
|
|
MAPLE
|
b:= proc(l) option remember; local n; n:= nops(l); `if`({l[]}={0},
1, add(`if`((l[i]-1<>n-i or i=1 or l[i-1]-1<=n-i) and l[i]>
`if`(i=n, 0, l[i+1]), b(subsop(i=l[i]-1, l)), 0), i=1..n))
end:
a:= n-> b([n$n]):
|
|
MATHEMATICA
|
b[l_List] := b[l] = Module[{n = Length[l]}, If[Union[l] == {0}, 1, Sum[If[ (l[[i]]-1 != n-i || i == 1 || l[[i-1]]-1 <= n-i) && l[[i]] > If[i == n, 0, l[[i+1]]], b[ReplacePart[l, i -> l[[i]]-1]], 0], {i, 1, n}]]];
a[n_] := b[Table[n, {n}]];
|