%I #18 May 04 2023 03:30:31
%S 1,1,2,1,5,3,1,11,15,4,1,23,57,34,5,1,47,195,200,65,6,1,95,633,1010,
%T 550,111,7,1,191,1995,4704,3850,1281,175,8,1,383,6177,20874,24255,
%U 11886,2646,260,9,1,767,18915,89800,143115,97272,31458,4992,369,10
%N Triangle T(n,k) = total of number at last index for all set partitions of n into k parts.
%H Alois P. Heinz, <a href="/A120095/b120095.txt">Rows n = 1..150, flattened</a>
%F T(n,k) = (k*(k+1)/2)*S2(n-1,k) + k*S2(n-1,k-1) = 1/2 (S2(n+1,k) + S2(n,k) - S2(n-1,k-2)) = k T(n-1,k) + T(n-1,k-1) + S2(n-2,k-2), where S2 is the Stirling numbers of the second kind (A008277).
%e The set partitions of 4 objects into 2 parts are {1,1,1,2}, {1,1,2,1}, {1,1,2,2}, {1,2,1,1}, {1,2,1,2}, {1,2,2,1} and {1,2,2,2}. The last terms of these sum to 2+1+2+1+2+1+2 = 11, so T(4,2) = 11.
%e Table starts:
%e 1;
%e 1, 2;
%e 1, 5, 3;
%e 1, 11, 15, 4;
%e 1, 23, 57, 34, 5;
%e 1, 47, 195, 200, 65, 6;
%e ...
%p b:= proc(n, m) option remember; `if`(n=0, 1, add((t->
%p `if`(n=1, j*x^t, b(n-1, t)))(max(m, j)), j=1..m+1))
%p end:
%p T:= n-> (p-> seq(coeff(p, x, i), i=1..n))(b(n, 0)):
%p seq(T(n), n=1..10); # _Alois P. Heinz_, Aug 02 2021
%t b[n_, m_]:= b[n, m]= If[n==0, 1, Sum[
%t If[n==1, j*x^#, b[n-1, #]]&[Max[m, j]], {j,m+1}]];
%t T[n_] := Table[Coefficient[#, x, i], {i, 1, n}]&[b[n, 0]];
%t Table[T[n], {n,10}]//Flatten (* _Jean-François Alcover_, Aug 19 2021, after _Alois P. Heinz_ *)
%o (Magma)
%o A120095:= func< n,k | (&+[Binomial(j+k,j+1)*StirlingSecond(n-1,k+j-1): j in [0..1]]) >;
%o [A120095(n,k): k in [1..n], n in [1..15]]; // _G. C. Greubel_, May 03 2023
%o (SageMath)
%o def A120095(n,k):
%o return sum(binomial(j+k,j+1)*stirling_number2(n-1,k+j-1) for j in range(2))
%o flatten([[A120095(n,k) for k in range(1,n+1)] for n in range(1,16)]) # _G. C. Greubel_, May 03 2023
%Y Cf. A008277, A120058.
%Y Row sums are A087648(n-1).
%K nonn,tabl
%O 1,3
%A _Franklin T. Adams-Watters_, Jun 07 2006