I want to know how many ways there are to choose $l$ elements in order from a set with $d$ elements, allowing repetition, such that no element appears more than $3$ times. I've thought of the following recursive function to describe this: $$C(n_1,n_2,n_3,0)=1$$ $$C(n_1,n_2,n_3,l)=n_1C(n_1-1,n_2,n_3,l-1)+n_2C(n_1+1,n_2-1,n_3,l-1)+n_3C(n_1,n_2+1,n_3-1,l-1)$$ The number of ways to choose the elements is then $C(0,0,d,l)$. Clearly there can be at most $3^l$ instances of the base case $C(n_1,n_2,n_3,0)=1$. Additionally, if $n_i=0$, that term will not appear in the expansion since zero times anything is zero.
It isn't too hard to evaluate this function by hand for very small l or by computer for small l, but I would like to find an explicit form. However, while I know how to turn recurrence relations with only one variable into explicit form by expressing them as a system of linear equations (on homogeneous coordinates if a constant term is involved) in matrix form, I don't know how a four variable equation such as this can be represented explicitly. There's probably a simple combinatorical formulation I'm overlooking. How can this function be expressed explicitly?