The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+1 vote

Following is the given solution in the solution manual:

I understood how we got x1 + x2 + x3 + x4 + x5 = 5, I understood too how we got x1+x2+x3+x4+x5 = 1, when x1>=4.

but I am unable to understand the highlighted part. how did we get x1 + x2 + x3 + x4 + x5 = 2. please explain.

PS: i solved this question using generating functions and i am getting the same answer as 106.

asked in Algorithms by Veteran (43.7k points) | 82 views

1 Answer

+1 vote
Best answer
We have $x_1 + x_2 + x_3 + x_4 + x_5 = 21 (0\leq x_1\leq 3,1\leq x_2<4,x_3\geq 15)$. Note that $x_2$ is strictly less than 4. Hence to help us solve the equation, we modify it by subtracting the lower bounds of the constraints from the total sum i.e 21. By doing that, there is also a modification to the upper bounds due to the fact that $x_2$ and $x_3$ are already assigned some value i.e 1 and 15 respectively.

We then have $x_1 + x_2' + x_3' + x_4 + x_5 = 5 (0\leq x_1\leq 3,0\leq x_2'\leq 2,x_3'\geq 0)$. The number of solutions for this equation without considering upper bounds is $\binom{5+5-1}{5} = \binom{9}{5} = 126$. Now we can subtract the #solutions for $x_1\geq4$ and $x_2'\geq3$. Both these conditions cannot hold simultaneously since the sum should be 5 and thus we needn't consider the intersection of the cases. We then would obtain $x_1 + x_2' + x_3' + x_4 + x_5 = 1$ and $x_1 + x_2' + x_3' + x_4 + x_5 = 2$ giving us 5 and 15 as #solutions respectively. (P.S: The second highlighted portion arises from solving for  $x_2'\geq3$). Subtracting these figures from 126 would fetch us 106.
answered by Boss (6.6k points)
We then have $x_1 + x_2' + x_3' + x_4 + x_5 = 5 (0\leq x_1\leq 3,0\leq x_2'\leq 2,x_3'\geq 0)$.

Based on what, you did this $0\leq x_2'\leq 2$? it was $x_2 \leq 3$.
Note that $x_2$ is strictly less than 4, which means $x_2\leq3$. Subtracting one from the lower bound also requires subtracting one from the upper bound.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

34,241 questions
40,932 answers
39,846 users