|xxxxx|xxxxx|xxxxx|xxxxx|xxxxx|xxxxx|xxxxx|xxxxx|You can see the eight bins, each holding up to 5 possible balls. Let's throw some balls in there and see what happens.
|OOxxx|xxxxx|Oxxxx|xxxxx|xxxxx|xxxxx|OOxxx|xxxxx|Here we've thrown two balls into bin 1, one into bin 3, and two into bin 7 — in other words, bought two #1 meals, one #3 meal, and two #7 meals. But in order to actually count these possibilities, we need a better representation. There's a lot of redundancy. If you naively count the possible strings of x's and O's ((5*8)2), there are a lot of duplicates:
|xxOOx|xxxxx|xxxxO|xxxxx|xxxxx|xxxxx|OxxOx|xxxxx|And even totally nonsensical results, with way too many balls:
|xxOOx|xxOOx|xxxxO|xOOOO|xOOOx|xxxxx|OOxOx|xxxxx|So let's try something. Let's try removing all the x's — the "empty spaces" — from our string. Here's our result in that form:
|OO||O||||OO||Now each character can be either a ball or a "barrier" between the boxes. Notice that as long as you have the same number of balls and barriers, you can move them around as much as you want and still end up with a valid result. Well, almost:
OOO|||||||||OOHmm, we missed the boxes completely! There's one more bit of redundancy left: every valid string has one "barrier" at each end. So let's remove them. Our result now becomes:
OO||O||||OO|And now every permutation of these characters is a valid result. The problem is now exactly like "how many distinct words can be formed by rearranging the letters in MISSISSIPPI?" First we count all the possible words; since the string is 5 (balls) + 7 (barriers) = 13 characters long, there are 13! possible permutations of it. Now we have to account for any times we over-counted. So let's take an example string — our result — and see how many times we actually count it. Let's number the O's, since they're being counted as distinct:
O1O2||O3||||O4O5| O1O3||O4||||O2O5| O5O2||O3||||O1O4| ...As you can see, for every possible permutation of the 5 balls, we count our result again. And it's the same for any string, not just the example we picked. So to eliminate these possibilities, we divide our total count by the number of ways to permute 5 balls, or 5!. We can go through a similar process for the barriers to find that we must divide again by 7!.
posted by kcm at 8:10 PM on July 3, 2007 [1 favorite]