Partition of integer with size constraint

393 Views Asked by At

A rather straightforward combinatorial question:

Given numbers $X, q, n$ such that $0 \leq X \leq n(q-1)$, what are the total number of ways to express $X$ as sum of $n$ numbers, where each summand is between $0$ and $q-1$ and the order does matter (e.g. $1+2$ and $2+1$ are considered different)?

I'd assume that there is an established formula for this but I couldn't find it via Google. If someone can give me a pointer to the result it would be much appreciated.

Thanks!

2

There are 2 best solutions below

1
On

You can form a recurrence. Add $1$ to all the summands to get rid of the zeros. Now we want the number of compositions of $X+n$ into $n$ parts of maximum size $q$. Let $N(X+n,n)$ be the desired number of compositions of $X+n$ into $n$ parts of size at most $q$. Then $$N(i,n)=\begin {cases} 0 & i \lt n\\ 1& i=n\\ \sum_{j=1}^q N(i-j,n-1) & i \gt n\end {cases} $$

0
On

Turned out "Composition" (en.wikipedia.org/wiki/Composition_(combinatorics)) is the name of the concept I was looking for. Thanks to Newb for pointing it out to me.