TITLE: Total number of solutions for a given equation with a minimum value $0$ and a maximum value of $m$
QUESTION [5 upvotes]: What is the total number of solutions for following equation 
$$x_1+x_2+x_3+.....+x_k=n$$
with a maximum value of $m$, where $0\leq x \leq m$. No two variables should contain a maximum value $m$.
Example: $x_1+x_2+x_3=3$ with a maximum value $2$ ($n=3$, $m=2$, $k=3$)
Total possible ways is $7$:
$$\{1,1,1\}, \{0,1,2\}, \{0,2,1\}, \{1,0,2\}, \{1,2,0\}, \{2,0,1\}, \{2,1,0\}$$
I've done it manually but I don't how to come up with a formula. I've been struggling for last one week.
Is there any formula?

REPLY [3 votes]: Hint: You can divide the solutions into two groups. One, those which attain the maximum value ($x_i = m$ for some  $i$, and $x_j < m$ for all $j\ne i$); the other, in which $x_i < m$ for all $i$.
Then you can count the cardinality of each set by looking into this question.
Specifically, adapting the linked pdf (formula E, page 441), we get that the number of compositions of $k$ numbers $0\le x_i<m$ with $\sum x_i = n$ is given by
$$F(n,m,k)= \sum_{j=0}^{\lfloor n/m \rfloor} (-1)^j {k \choose j}{n+k - j \, m -1 \choose k-1}$$
Then we have
$$C(n,m,k) = k \, F(n-m,m,k-1) + F(n,m,k) $$
In your example:
$$C(3,2,3) = 3 \, F(1,2,2) + F(3,2,3) = 3 \times 2 + 1 = 7$$