Maths WorkshopMaths problems with full solutions
Exercise 1255Combinatorics › Inclusion-exclusionM1Added 4 Nov 2026

Stars and bars with upper bounds

#stars and bars#inclusion-exclusion#counting#compositions

Statement

  1. How many ordered quadruples (x1,x2,x3,x4)(x_1,x_2,x_3,x_4) of integers satisfy x1+x2+x3+x4=20x_1+x_2+x_3+x_4=20 and 1≤xi≤81\le x_i\le8 for every ii?
  2. Prove that the number of non-negative integer solutions of y1+⋯+yk=my_1+\dots+y_k=m is (m+k−1k−1)\binom{m+k-1}{k-1}.
Hint

Subtract 11 from each variable to start at 00. Count all solutions, then remove those with some variable ≥8\ge8 by inclusion-exclusion.

Show solutionHide solution

Solution

2. (Stars and bars.) Write mm stars in a row and place k−1k-1 bars among them; the bars cut the row into kk groups of stars whose sizes are y1,…,yk≥0y_1,\dots,y_k\ge0 with sum mm, and every solution arises exactly once. A configuration is a sequence of m+k−1m+k-1 symbols of which k−1k-1 are bars: (m+k−1k−1)\binom{m+k-1}{k-1} possibilities.

1. Put yi=xi−1y_i=x_i-1, so 0≤yi≤70\le y_i\le7 and y1+⋯+y4=16y_1+\dots+y_4=16.

  • All non-negative solutions: (193)=969\binom{19}{3}=969.
  • Let AiA_i be the set of solutions with yi≥8y_i\ge8. Substituting yi=8+ziy_i=8+z_i gives zz-sum 88: (113)=165\binom{11}{3}=165 solutions, for each ii.
  • Two variables ≥8\ge8: the sum would be ≥16\ge16 with equality: yi=yj=8y_i=y_j=8 and the other two 00, giving (33)=1\binom{3}{3}=1 solution for each of the (42)=6\binom42=6 pairs.
  • Three variables ≥8\ge8 would need sum ≥24>16\ge24>16: impossible.

By inclusion-exclusion the answer is
969−4⋅165+6⋅1=315.969-4\cdot165+6\cdot1=315.

Check. Direct enumeration by computer gives 315315.

Remark. Equivalently, 315315 is the coefficient of x16x^{16} in (1−x81−x)4\left(\frac{1-x^8}{1-x}\right)^4.

Lesson. Stars and bars counts unconstrained solutions; upper bounds are handled by inclusion-exclusion on the violations.