Finding number of nonnegative solutions for the equation $x_1+ x_2+ x_3+ x_4+ x_5=9$ when $x_1 \geq 1, x_5 \leq 5$

combinatoricsdiscrete mathematicsinclusion-exclusion

I need to find the number of nonnegative solutions for the equation $$x_1+ x_2+ x_3+ x_4+ x_5=9$$ when $x_1 \geq 1, x_5 \leq 5$.

I know I need to use $\binom{n+k-1}{k-1}$ and Inclusion–exclusion, but I'm not sure how to use it properly with the conditions.

It will be great if someone will explain to me how to choose the $n,k$.

Best Answer

In general with stars and bars we find that there are $\binom{n+k-1}{k-1}$ solutions for:$$y_1+\cdots+y_n=k$$where the $y_i$ are nonnegative integers.

In your case we can at first hand go for $n=5$, $y_1=x_1-1$, $y_i=x_i$ for $i=2,3,4,5$ and $k=9-1=8$.

Then however we overlooked the constraint $y_5=x_5\leq5$.

This can be repaired by subtracting the number of solutions that satisfy $y_5\in\{6,7,8\}$ or equivalently: $$y_1+y_2+y_3+y_4\in\{0,1,2\}$$

Again using stars and bars (3 times) we can find these numbers.

Related Question