%I #12 Jan 10 2022 03:07:00
%S 1,1,1,1,11,1,1,57,57,1,1,247,930,247,1,1,1013,10006,10006,1013,1,1,
%T 4083,89139,225230,89139,4083,1,1,16369,719691,3771323,3771323,719691,
%U 16369,1,1,65519,5495836,53239541,108865438,53239541,5495836,65519,1
%N Triangle T(n, k, m) = (m*(n-k) + 1)*T(n-1, k-1, m) + (m*k + 1)*T(n-1, k, m) + m*k*(n-k)*T(n-2, k-1, m) with T(n, 0, m) = T(n, n, m) = 1 and m = 3, read by rows.
%H G. C. Greubel, <a href="/A157149/b157149.txt">Rows n = 0..50 of the triangle, flattened</a>
%F T(n, k, m) = (m*(n-k) + 1)*T(n-1, k-1, m) + (m*k + 1)*T(n-1, k, m) + m*k*(n-k)*T(n-2, k-1, m) with T(n, 0, m) = T(n, n, m) = 1 and m = 3.
%F T(n, n-k, 3) = T(n, k, 3).
%F T(n, 1, 3) = A289255(n). - _G. C. Greubel_, Jan 09 2022
%e Triangle begins as:
%e 1;
%e 1, 1;
%e 1, 11, 1;
%e 1, 57, 57, 1;
%e 1, 247, 930, 247, 1;
%e 1, 1013, 10006, 10006, 1013, 1;
%e 1, 4083, 89139, 225230, 89139, 4083, 1;
%e 1, 16369, 719691, 3771323, 3771323, 719691, 16369, 1;
%e 1, 65519, 5495836, 53239541, 108865438, 53239541, 5495836, 65519, 1;
%p A157149 := proc(n,k)
%p option remember;
%p if k < 0 or k> n then 0;
%p elif k = 0 or k = n then 1;
%p else (3*(n-k)+1)*procname(n-1,k-1) + (3*k+1)*procname(n-1,k) + 3*k*(n-k)*procname(n-2,k-1);
%p end if;
%p end proc:
%p seq(seq(A157149(n,k),k=0..n),n=0..10) ; # _R. J. Mathar_, Feb 06 2015
%t T[n_, k_, m_]:= T[n, k, m]= If[k==0 || k==n, 1, (m*(n-k)+1)*T[n-1,k-1,m] + (m*k+1)*T[n-1,k,m] + m*k*(n-k)*T[n-2,k-1,m]];
%t Table[T[n,k,3], {n,0,10}, {k,0,n}]//Flatten (* modified by _G. C. Greubel_, Jan 09 2022 *)
%o (Sage)
%o @CachedFunction
%o def T(n,k,m): # A157149
%o if (k==0 or k==n): return 1
%o else: return (m*(n-k) +1)*T(n-1,k-1,m) + (m*k+1)*T(n-1,k,m) + m*k*(n-k)*T(n-2,k-1,m)
%o flatten([[T(n,k,3) for k in (0..n)] for n in (0..20)]) # _G. C. Greubel_, Jan 09 2022
%Y Cf. A007318 (m=0), A157147 (m=1), A157148 (m=2), this sequence (m=3), A157150 (m=4), A157151 (m=5).
%Y Cf. A157152, A157153, A157154, A157155, A157156, A157207, A157208, A157209, A157210, A157211, A157212, A157268, A157272, A157273, A157274, A157275.
%Y Cf. A289255.
%K nonn,tabl,easy
%O 0,5
%A _Roger L. Bagula_, Feb 24 2009
%E Edited by _G. C. Greubel_, Jan 09 2022