In a word problem, they say a guy has 14 cats, dogs, and Guiana pigs. What are all the possible combinations the guy could have? I don't understand how to solve this problem. I tried my own ways but none of them work. Can you please help me?
-
3Welcome to StackExchange! It might be more useful if you posted the exact question up here, rather than trying to summarise it, which is slightly confusing. Also, showing people what you have done is usual on this site, as it means people can write answers which are at your level of knowledge – lioness99a Jun 12 '17 at 14:21
-
5Shouting won't help. Your phrasing isn't entirely clear but I suspect you mean: given that the fellow has exactly $c$ cats, $d$ dogs, $g$ guinea pigs and $c+d+g=14$, how many possibilities for the triple $(c,d,g)$ are there? If so, that can be done by hand or you might want to read about Stars and Bars – lulu Jun 12 '17 at 14:23
-
3Note also, that since you say "I tried my own ways but none of them work," you should show examples of such work. How do you know they failed? – amWhy Jun 12 '17 at 14:44
4 Answers
Here's a hint on applying stars and bars to your problem.
The guy has $14$ animals of some combination of type. The animals are the "stars":
$$\star\star\star\star\star\star\star\star\star\star\star\star\star\star$$
You can divide the starts into three groups using $3-1=2$ "bars." Here's one way:
$$\star\star\star | \star\star\star\star\star\star | \star\star\star\star\star$$
If we say that the first, second, and third groups are cats, dogs, and guinea pigs, respectively, then the above situation would count the case of $3$ cats, $6$ dogs, and $5$ guinea pigs.
You can also have something like this:
$$\star\star\star\star\star\star\star || \star\star\star\star\star\star\star$$
There are no stars between the bars, so therefore no dogs! (Which is sad, but I digress.) In other words, he has $7$ cats and $7$ guinea pigs.
Or, a much happier situation:
$$|\star\star\star\star\star\star\star\star\star\star\star\star\star\star|$$
$14$ dogs, and no other types.
It boils down to figuring out the number of places you can put the bars.
Can you take it from here?

- 26,319
-
-
-
1Well, I love dogs too, so we can hope for zero guinea pigs to maximize the cats and dogs! (Oops: there's always the protest: "Guinea Pigs have rights too!"). Anyway, it's a good answer, which I've already upvoted. – amWhy Jun 12 '17 at 15:10
-
1@amWhy I'm more allergic to cats than dogs, and my wife is very allergic to guinea pigs, so there you go. – John Jun 12 '17 at 17:53
-
1I'm allergic to all three, the most severe of my allergies to animals being to cats. But I have 2-kitty-furr-babies, any way (perhaps I need help for dealing with masochism :) ). I'd love a dog as well; currently I don't have the space for one, and I can't even think of adopting a doggy until my lease expires, and I can move! – amWhy Jun 12 '17 at 18:21
We can also solve the problem with a little dose of algebra.
Zero or more cats give $$1+x+x^2+\cdots=\frac{1}{1-x}$$
The same holds for dogs as well as for Guiana pigs. Putting all together gives zero or more cats, dogs and Guiana pigs: $$\left(\frac{1}{1-x}\right)^3$$
Since we want all combinations of $14$ cats, dogs and Guiana pigs, we calculate
\begin{align*} \color{blue}{[x^{14}]\left(\frac{1}{1-x}\right)^3}&=[x^{14}]\sum_{n=0}^\infty \binom{n+2}{2}x^n=\binom{16}{2}\color{blue}{=120} \end{align*}

- 108,315
-
OK, this is probably the third time in a week I've seen this kind of answer to a combinatorics problem (+1 BTW), and I admit I don't have the background to know where it comes from. Is this a generating-function thing, or is the background / defining theorem something else? – John Jun 12 '17 at 17:51
-
1@John: Thanks and yes, it is based upon generating functions. You might find this answer helpful. – Markus Scheuer Jun 12 '17 at 17:58
-
@MarkusScheuer I would not say this is based on ogf, this is the essence of ogf! – yo' Jun 12 '17 at 22:26
This is a stars and bars problem.
Theorem 1: in this case, we require that we must include at least one of each animal to be chosen from 14, this is ${n -1 \choose k - 1}$ where $n$ is the number of animals needed (14), and $k$ the number of types of animals under consideration. There are $\binom{14 - 1}{3 - 1}$ ways of choosing 14 pets, such that at least one cat, at least one dog, and at least 1 Guinea Pig.
Theorem 2 This variation applies to situation in which we need to include the possibility that one or two of the types of animals might be zero: For example we count the possibility that we end with 6 cats, 0 dogs, and 8 Guinea Pigs; and we also count the possibility that we end up with 14 cats, no dogs, no Guinea pigs.
In this case, we use the following formula (again see the link to Theorem 2 given above: ${n+k - 1 \choose n }$, where $n$ is the number of animals sought, and $k$ is the number of types to choose, so in this case, we have ${ 14 + 3 - 1 \choose 14} = \binom{16}{14}=\binom{16}{2} = \frac{16!}{14!\cdot 2!}$
-
Your answer assumes that the asker is familiar with "stars and bars" problems. – amWhy Jun 12 '17 at 14:45
-
You are also assuming there is at least one cat, at least one dog, and at least one guinea pig. The correct formula should be $$\binom{14 + 3 -1}{14} = \binom{16}{14} = \frac{16!}{14!\cdot 2!}$$ – amWhy Jun 12 '17 at 14:50
-
-
Duncan, take my edits as suggestions for a clearer and more precise answer (specifying what represents k,what represents n, why there there are actually two methods employing "stars and bars", and when one applies, vs. the other.) Of course, you are free to roll-back to your last edit by clicking on the link immediately above the icon in the Lower center of the post (most recent editor). – amWhy Jun 12 '17 at 15:41
This is how I will model it: each o (of a total of 14) represents one animal and there are two / to divide them into three group; first group will be cats, second one dogs and the last one pigs.
An example demonstration: ooo/oo/ooooooooo This is 3 cats, 2 dogs and 9 pigs.
You got the idea. So basically, the question is how many permutations of 14 o's and 2 /'s exist. The answer is $\frac{16!}{14!2!}$, which is "16 choose 2".
Notice that this model allows zero number of animals such as /o/ooooooooooooo is 0 cats, 1 dog, 13 pigs. If you want at least 1 for each, you then assign 1 to each, leaving $14-3=11$ free assignments and you repeat the idea above as if you have 11 animals in total, in the end you add 1 more to each number because you pre-assigned 1 to each to prevent zero number for each of them.
If the number of animals is $x$ (instead of 14), and number of type of animals is $y$ (instead of 3), the formula reduces to "(x+y-1) choose (y-1)"