How many integer solutions to a linear combination, with restrictions?

First restrict only so that $x_1 + \cdots + x_5 = 21$ and $x_i \geq 0$ for $i = 1,2,3,4,5$. I.e., first forget about the "cap" on each of the five $x$'s. Then, as you say, there are $\binom{25}{4}$ solutions. Next note that if any one components, let's say $x_1$ for example, is $\geq 11$, then the sum of the others is $\leq 10$. This means each one of the other four components is $\leq 10$ or else at least one is negative, which we've ruled out already. This greatly restricts the complication of the full inclusion-exclusion technique you'd otherwise need to use. Let's count how many of the $\binom{25}{4}$ solutions have a component $\geq 11$. Relabel the numbers so that the offending $x$ is $x_1$. If we define $y_1 = x_1 - 11$, we can write $$y_1 + x_2 +\cdots+x_5 = 10\,,$$ where it still holds that $0 \leq y_1,x_2,x_3,x_4,x_5 \leq 10$. How many solutions of this equation? $\binom{14}{4}$ by the same reasoning as before. We must sutract these solutions from the original $\binom{25}{4}$ solutions because each one of these violated the restriction that $x_1 \leq 10$. We must also subtract the number of solutions with $x_2$,$x_3$, $x_4$ or $x_5$ out of the allowed range. But by the obvious symmetry of the constraints, each one of these is the same as the $x_1$ case. So, the overall number of allowed solutions is $$\binom{25}{4} - 5\times\binom{14}{4}$$.

As an exercise, try counting how many solutions to $x_1 + \cdots x_5 = 22$ lie within $x_1,\ldots,x_5 \leq 10$. If you do it right, the equations don't get too ugly. Good luck and have fun!


You've counted the general non-negative solutions to the equation. Now suppose that we want to count the number of solutions in which $x_1 > 10$. This is the same as counting the number of non-negative solutions to $$(x_1 - 11) + x_2 + \cdots + x_5 = x_1' + x_2 + \cdots + x_5 = 10$$ Now if you can repeat this process for each variable and for each combination of variables (most are trivial) and if you then apply the principle of inclusion and exclusion, we can filter out the solutions in which the the variables are larger than $10$.

This is explained in much better detail in Brian's excellent answer linked in the comments.