Find the number of solutions to $n_1 +n_2 + n_3 + n_4 = 12$ when values of $n_k$ have restrictions

Solution 1:

Let $A$ denote nonnegative solutions to $n_1+n_2+n_3+n_4=12$ and $A_i$ denote those solutions where the upper bound on $n_i$ is violated, then inclusion/exclusion gives $$|\overline{A_1\cup A_2\cup A_3\cup A_4}|=|A|-(|A_1|+|A_2|+|A_3|+|A_4|)+(|A_1\cap A_2|+\cdots)-\cdots\\ =\binom{12+4-1}{12}-\left(\binom{7+4-1}7+\binom{6+4-1}6+\binom{3+4-1}3+\binom{2+4-1}2\right)+\binom{1+4-1}1$$ where e.g. $|A_1|=\binom{7+4-1}7$ because the solutions there can be recast as solutions to $(m_1+5)+n_2+n_3+n_4=12$ with $m_1,n_i\ge0$ or $m_1+n_2+n_3+n_4=7$, and omitted terms are because they are empty (i.e. they reduce to a sum of nonnegative integers to a negative integer).