%I #19 Jul 10 2019 10:24:01
%S 1,0,1,1,0,1,0,2,0,3,1,0,2,0,2,0,3,0,8,0,10,1,0,3,0,5,0,5,0,4,0,15,0,
%T 30,0,35,1,0,4,0,9,0,14,0,14,0,5,0,24,0,63,0,112,0,126,1,0,5,0,14,0,
%U 28,0,42,0,42,0,6,0,35,0,112,0,252,0,420,0,462
%N Triangle read by rows, generalized ballot numbers, 0<=k<=n.
%C Compare with the definition of the Motzkin triangle A238763.
%D D. E. Knuth, TAOCP, Vol. 4a, Section 7.2.1.6, Eq. 22, p. 451.
%H P. Luschny, <a href="http://oeis.org/wiki/User:Peter_Luschny/TheLostCatalanNumbers">The lost Catalan numbers</a>
%F Definition: T(0, 0) = 1; T(p, q) = 0 if p < 0 or p > q; T(p, q) = T(p-2, q) + (q mod 2) T(p-1, q-1) + T(p, q-2). (The notation is in the style of Knuth, TAOCP 4a (7.2.1.6)).
%F T(2*k, 2*n) are the classical ballot numbers A009766(n, k).
%F T(2*k-1, 2*n-1) = A238761(n, k).
%F T(n,k) = c*A189231(a, b) with a = floor((n + k + (k mod 2))/2), b = floor((n-k)/2) and c = ((n+k+1) mod 2).
%F T(n, k) = ((n+k+1) mod 2)*(floor(n/2)+floor(k/2) + 1)^(k mod 2)) * (binomial(floor(n/2) + floor(k/2), floor(n/2)) - binomial( floor(n/2) + floor(k/2), floor(n/2) + 1)).
%F T(n, k) = ((n+k+1) mod 2)*(floor(n/2)+floor(k/2) + 1)^(k mod 2)) *(floor((n-k)/2) + 1)/(floor(n/2) + 1) * binomial( floor(n/2) + floor(k/2), floor(n/2)).
%F T(n, n) = A057977(n).
%F T(n, n-2) = A238452(n-1).
%F Row sums are A238879.
%e [n\k 0 1 2 3 4 5 6 7]
%e [0] 1,
%e [1] 0, 1,
%e [2] 1, 0, 1,
%e [3] 0, 2, 0, 3,
%e [4] 1, 0, 2, 0, 2,
%e [5] 0, 3, 0, 8, 0, 10,
%e [6] 1, 0, 3, 0, 5, 0, 5,
%e [7] 0, 4, 0, 15, 0, 30, 0, 35.
%p binom2 := proc(n, k) local h;
%p h := n -> (n-((1-(-1)^n)/2))/2;
%p n!/(h(n-k)!*h(n+k)!) end:
%p A238762 := proc(n, k) local a,b,c;
%p a := iquo(n+k+2+modp(n,2), 2);
%p b := iquo(n-k+2, 2);
%p c := modp(n+k+1, 2);
%p binom2(a,b)*b*c/a end:
%p seq(print(seq(A238762(n, k), k=0..n)), n=0..7);
%p # Alternativ:
%p ballot := proc(p, q) option remember;
%p if p = 0 and q = 0 then return 1 fi;
%p if p < 0 or p > q then return 0 fi;
%p ballot(p-2, q) + ballot(p, q-2);
%p if type(q, odd) then % + ballot(p-1, q-1) fi;
%p % end:
%t T[n_, k_] := T[n, k] = Which[k == 0 && n == 0, 1, k < 0 || k > n, 0, True, s = T[n, k - 2] + T[n - 2, k]; If[OddQ[n], s += T[n - 1, k - 1]]; s];
%t Table[T[n, k], {n, 0, 11}, {k, 0, n}] // Flatten (* _Jean-François Alcover_, Jul 10 2019, adapted from Sage code *)
%o (Sage)
%o @CachedFunction
%o def ballot(p, q):
%o if p == 0 and q == 0: return 1
%o if p < 0 or p > q: return 0
%o S = ballot(p-2, q) + ballot(p, q-2)
%o if q % 2 == 1: S += ballot(p-1, q-1)
%o return S
%o for q in range(8): [ballot(p, q) for p in (0..q)]
%Y Cf. A009766, A189231, A238761, A238879.
%K nonn,tabl
%O 0,8
%A _Peter Luschny_, Mar 05 2014