|
MATHEMATICA
|
(* G computes the required sequence, F computes the similar sequence with any monotone sequence permitted as the input top row. Note that F and Bifurcate cache their values. *) Bifurcate[l_] := Bifurcate[l] = If[Length[l] == 1, { {} }, Union[Map[Prepend[ #, l[[1]]] &, Bifurcate[Drop[l, 1]]], Map[ Prepend[ #, l[[2]]] &, Bifurcate[Drop[l, 1]]]]] F[l_] := F[l] = If[Length[l] == 0, 1, Apply[Plus, Map[F, Bifurcate[l]]]] G[n_] := F[Range[n]]
|