%I #9 Jan 23 2022 07:37:02
%S 1,1,1,1,5,1,1,15,15,1,1,37,95,37,1,1,82,463,463,82,1,1,173,1910,3799,
%T 1910,173,1,1,356,7096,25672,25672,7096,356,1,1,723,24645,150994,
%U 260519,150994,24645,723,1,1,1458,81499,804875,2259903,2259903,804875,81499,1458,1
%N Triangle T(n, k, q) = (q*(n-k) +1)*T(n-1, k-1, q) + (q*k+1)*T(n-1, k, q) + q*A157522(n, k)*T(n-2, k-1, q), with T(n, 0, q) = T(n, n, q) = 1 and q = 1, read by rows.
%H G. C. Greubel, <a href="/A157523/b157523.txt">Rows n = 0..50 of the triangle, flattened</a>
%F T(n, k, q) = (q*(n-k) +1)*T(n-1, k-1, q) + (q*k+1)*T(n-1, k, q) + q*A157522(n, k)*T(n-2, k-1, q), with T(n, 0, q) = T(n, n, q) = 1 and q = 1.
%e Triangle begins as:
%e 1;
%e 1, 1;
%e 1, 5, 1;
%e 1, 15, 15, 1;
%e 1, 37, 95, 37, 1;
%e 1, 82, 463, 463, 82, 1;
%e 1, 173, 1910, 3799, 1910, 173, 1;
%e 1, 356, 7096, 25672, 25672, 7096, 356, 1;
%e 1, 723, 24645, 150994, 260519, 150994, 24645, 723, 1;
%e 1, 1458, 81499, 804875, 2259903, 2259903, 804875, 81499, 1458, 1;
%t f[n_, k_]= 1 + If[k<=Floor[n/4], k, If[Floor[n/4]<k<=Floor[n/2], Floor[n/2]-k, If[Floor[n/2]<k<=Floor[3*n/4], k-Floor[n/2], n-k]]];
%t A157522[n_, k_]:= f[n,k] +f[n,n-k] -1;
%t T[n_, k_, q_]:= T[n,k,q]= If[k==0 || k==n, 1, (q*(n-k) +1)*T[n-1,k-1,q] + (q*k+1)*T[n-1, k, q] + q*A157522[n, k]*T[n-2,k-1,q]];
%t Table[T[n,k,1], {n,0,10}, {k,0,n}]//Flatten (* modified by _G. C. Greubel_, Jan 23 2022 *)
%o (Sage)
%o def f(n, k):
%o if (k <= (n//4)): return k+1
%o elif ((n//4) < k <= (n//2)): return (n//2)-k+1
%o elif ((n//2) < k <= (3*n//4)): return k+1-(n//2)
%o else: return n-k+1
%o def A157522(n,k): return f(n,k) + f(n,n-k) - 1
%o @CachedFunction
%o def T(n, k, q):
%o if (k==0 or k==n): return 1
%o else: return (q*(n-k) +1)*T(n-1, k-1, q) + (q*k+1)*T(n-1, k, q) + q*A157522(n, k)*T(n-2, k-1, q);
%o flatten([[T(n,k,1) for k in (0..n)] for n in (0..15)]) # _G. C. Greubel_, Jan 23 2022
%Y Cf. A007318 (q=0), this sequence (q=1).
%Y Cf. A157522.
%K nonn,tabl
%O 0,5
%A _Roger L. Bagula_, Mar 02 2009
%E Edited by _G. C. Greubel_, Jan 23 2022