How many solutions are there to $x+y+z=14$ where $x,y,z$ are all non-negative integers, $x \leq 5, y \leq 6, z \leq 7$?

Through using brute force, I have got 15 triplets of solutions. Have I reached the right answer, and how can I not use brute force?


For the given conditions, the maximum values of x, y and z are: $$\begin{align} x={} & 5 \\ y= {} & 6\\ z = {} & 7 \\ \sup(x+y+z) = {} & 18 \end{align}$$

Hence we must subtract 4 from $x$, $y$ and $z$ collectively such that $x+y+z=14$.

Of the 5 partitions of 4, all except 1+1+1+1 are possible allocations.

  • 4+0+0 - ${3\choose1}=3$ ways of allocating.
  • 3+1+0 - $3!=6$ ways of allocating.
  • 2+2+0- ${3\choose1}=3$ ways of allocating.
  • 1+1+2- ${3\choose1}=3$ ways of allocating.

Thus, as you calculated, $3+6+3+3=15$ integer solutions.


Here is another way to solve the problem.

Since, $x \leq 5, y \leq 6$ and $z \leq 7$, we can define $x_1, x_2, x_3$ as $5-x,6-y$ and $7-z$ respectively. Clearly, $x_1, x_2$ and $x_3$ are all non-negative integers. The original equation can thus be rewritten as

$$x_1 + x_2 + x_3 = 4$$

This has $\binom{4+2}{2} = 15$ solutions.


Using generating functions, like in this example $$x_1+x_2+x_3=14$$ $$0\leq x_1 \leq5$$ $$0\leq x_2 \leq6$$ $$0\leq x_3 \leq7$$ the generating function is $$(1+x+...+x^5)(1+x+...+x^6)(1+x+...+x^7)$$ and the coefficient near $x^{14}$ term is the answer, which is 15.