In how many ways can points be assigned to five questions with one to four points per question so that the total is $14$? A professor must write an exam with $5$ questions. Question number i should give $p_i \in \mathbb{Z}$ points. The sum of the points must be $14$ and each question must give at least $1$ point and a maximum of $4$ points. In how many ways can he distribute the points on the questions?
I first turned $p_i= x_i - 1$ so I can get $0 \le x_i \le 3$ instead. Then I put the variable $x_i$ in the equation and got $x_1 + x_2 + x_3 + x_4 + x_5 = 9$. The total amount of combination is $C(tot) = C(5+9-1, 9)= C(13, 4)$. What I then did was find how many combinations there are when one $x$ can be greater than $3$, and then when $2$ can be greater than $3$. $C_1 = C(9,4)C(5,1)$ and $C_2 = C(5,4)C(5,2)$. So the answer is $C(13,4) - C(9,4)C(5,1) - C(5,4) C(5,2)$
What my answer sheet says is, $C = C(13,4) - C(9,4)C(5,1) + C(5,4) C(5,2) = 715-630+50= 135$ What I answered was $715 - 105 - 50 = 560$ How is $C(9,4)C(5,1)= 630$? Besides why did they do $+50$ instead of $-50$??
Can anyone help me ?
 A: If $p_i$ points are assigned to the $i$th question, with each $p_i$ a positive integer satisfying $1 \leq p_i \leq 4$, and the examination has a total of $14$ points, $1 \le i \le 5$, then
$$p_1 + p_2 + p_3 + p_4 + p_5 = 14 \tag{1}$$
is an equation in the positive integers subject to the restrictions $p_i \leq 4$, $1 \le i \le 5$.
Following your method of converting the equation into the nonnegative integers, we let $x_i = p_i - 1$, $1 \le i \le 5$.  Then each $x_i$ is a nonnegative integer.  Substituting $x_i + 1$ for $p_i$, $1 \le i \le 5$, in equation $1$ and simplifying yields
$$x_1 + x_2 + x_3 + x_4 + x_5 = 9 \tag{2}$$
which is an equation in the nonnegative integers subject to the restrictions that $x_i = p_i - 1 \leq 4 - 1 = 3$, $1 \leq i \leq 4$.
If we temporarily ignore the restrictions, equation $2$ has
$$\binom{9 + 5 - 1}{5 - 1} = \binom{13}{4}$$
solutions in the nonnegative integers.
From these, we must subtract those cases in which one or more of the $x_i$s exceeds $3$.  Since the $x_i$s are nonnegative integers, at most two variables can exceed $3$ since $3 \cdot 4 = 12 > 9$.
There are five ways to choose a variable that exceeds $3$.  Suppose it is $x_1$.  Then $x_1 \geq 4$.  Let $x_1' = x_1 - 4$.  Then $x_1'$ is a nonnegative integer.  Substituting $x_1' + 4$ for $x_1$ in equation $2$ and simplifying yields
$$x_1' + x_2 + x_3 + x_4 + x_5 = 5 \tag{3}$$
which is an equation in the nonnegative integers with
$$\binom{5 + 5 - 1}{5 - 1} = \binom{9}{4}$$
solutions.  Therefore, there are
$$\binom{5}{1}\binom{9}{4}$$
solutions in which a variable exceeds $3$.
However, if we subtract this amount from the total, we will have subtracted too much.  This is because we will have subtracted each case in which two of the variables exceed $3$ twice, once for each way we could have designated one of the variables as the variable that exceeds $3$.  We only want to subtract such cases once, so we must add them to the total.
There are $\binom{5}{2}$ ways to select two of the five variables to exceed $3$.  Suppose they are $x_1$ and $x_2$.  Then $x_1 \geq 4$ and $x_2 \geq 4$.  Let $x_1' = x_1 - 4$ and $x_2' = x_2 - 4$.  Then $x_1'$ and $x_2'$ are nonnegative integers.  Substituting $x_1' + 4$ for $x_1$ and $x_2' + 4$ for $x_2$ in equation $2$ and simplifying yields
$$x_1' + x_2' + x_3 + x_4 + x_5 = 1 \tag{4}$$
which is an equation in the nonnegative integers with five solutions.  Hence, there are
$$\binom{5}{2}\binom{1 + 5 - 1}{5 - 1} = \binom{5}{2}\binom{5}{4}$$
solutions in which two variables exceed $3$.
By the Inclusion-Exclusion Principle, the number of ways the professor can distribute the points to the five questions so that each question is worth a positive integer number of points that is at most $4$ is
$$\binom{13}{4} - \binom{5}{1}\binom{9}{4} + \binom{5}{2}\binom{5}{4}$$
A: Our generating function is
$\begin {align*}
f(x)&=\left ( x+x^2+x^3+x^4 \right )^5\\&=x^5\left ( \frac{1-x^4}{1-x} \right )^5
\end{align*}$
So the answer is
$\begin {align*}
[x^{14}]f(x)&=[x^9]\left ( 1-5x^4+10x^8-h(x) \right )\sum_{k=0}^{\infty }\binom{-5}{k}(-x)^k\\&=\left ( [x^9]-5[x^5]+10[x] \right )\binom{k+4}{4}\\&=\binom{13}{4}-5\binom{9}{4}+10\binom{5}{4}\\&=\boldsymbol {135}
\end{align*}$
A: If you are using stars and bars, be alert to a way to reduce/eliminate inclusion-exclusion.
Here I transform the problem as $5$ boxes (ie $4$ bars) with $4$ marks each from which I can withdraw zero to three marks (corresponding to giving $4-1$ marks) from any box and I need to withdraw a total of $6$ marks.
Note that now only one box can violate restrictions.
Then by stars and bars it becomes
$$\binom{4+4}{4} -\binom51\binom{2+4}4=135$$
