# Repetition with restrictions [duplicate]

Your local grocery store just received a large shipment of apples, oranges, pears, and bananas---there are only 5 of each fruit. You are shopping at the store and will purchase your fruit for the week.

How many ways can you select $10$ pieces of fruit from your store's supply of apples, oranges, pears, and bananas, if you need at least $2$ oranges and $1$ apple?

I understand that there are 17 spots to choose from because 3 have been chosen and there are a total of 20 fruits. Would I use the combination by repetition formula? I can't quite wrap my head around what to do. Any help would be appreciated.

## marked as duplicate by N. F. Taussig combinatorics StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 26 '17 at 23:01

• Yes. You need to solve the equation $a + b + o + p = 7$ subject to the restrictions that $a \leq 4$, $b \leq 5$, $o \leq 3$, and $p \leq 5$. – N. F. Taussig Nov 26 '17 at 20:48
• In the case of the combination formula (17 + r -1 choose 17). What would my r be? – Safder Aree Nov 26 '17 at 21:05
• Why are you using $17$? You are only selecting an additional $7$ pieces of fruit. Please see my answer to this version of the question you posed. – N. F. Taussig Nov 26 '17 at 21:25
• I looked over your solution. I see you approached it using the stars and bars method. How would I represent a <= 4 in terms of y? y = a+4? – Safder Aree Nov 26 '17 at 21:35
• If there were no restrictions, the number of solutions would be $\binom{7 + 3}{3} = \binom{10}{3}$. From there, we must address the restrictions. Suppose $a > 4$. Then $a' = a - 5$ is a nonnegative integer. Substituting $a' + 5$ for $a$ in the equation $a + b + o + p = 7$ yields $a' + b + o + p = 2$, so $\binom{2 + 3}{3} = \binom{5}{3}$ solutions violate the restriction $a \leq 4$. – N. F. Taussig Nov 26 '17 at 21:41

As N. F. Taussig stated in the comments above, you need to solve for how many solutions (among non negative integers) has the equation:

$$\tag{I}a+o+p+b=7$$ with restrictions $a\le4, o\le3, p\le5, b\le5$

If there were no restrictions, then the equation (I) has ${{7+4-1}\choose{7}}=120$ non negative solutions.

But you need to subtract those who "violate" the restrictions (separately):

First ($a\le4$)

If $a\ge5$, this violates the first restriction. Let $y=a-5\ge0$, the equation becomes:

$$y+o+p+b=2$$ which has ${{2+4-1}\choose{2}}=10$ non negative solutions

Second ($o\le3$)

$o\ge4$ violates the second restriction. Let $z=o-4\ge0$, the equation becomes: $$a+z+p+b=3$$ which has ${{3+4-1}\choose{3}}=20$ non negative solutions

Third ($p\le5$)

$p\ge6$ violates the third restriction. Let $w=p-6\ge0$, the equation becomes: $$a+o+w+b=1$$ which has ${{1+4-1}\choose{1}}=4$ non negative solutions

Fourth ($b\le5$)

Analogously to the previous one, there are ${{1+4-1}\choose{1}}=4$ solutions who violate the fourth restriction

In total we have $10+20+4+4=38$ solutions of equation (I) such that do not follow the restrictions. Therefore, there are $120-38=82$ solutions