TITLE: Permutations with restriction
QUESTION [6 upvotes]: We have $n$ types of objects, the number of objects of type $i$ being $a_i$, $1\leq i\leq n$.
What is the number of permutations of the 
$\sum_{i=1}^n a_i$ objects, if no two objects of the same type may be next to each other?
A simple example: If we have the objects $\{a,a,a,b,b,c,c\}$, then we allow $abcabac$ but not $aaabbcc$.
I have searched the web. The only results I found were about permutations of (pairwise) different objects avoiding certain patterns. 
I put this question on math.stackexchange.com but haven't received an answer.

REPLY [11 votes]: There's a nice result, I think due to Carlitz, Scoville, and Vaughan (I learned it as the "Carlitz-Scoville-Vaughan theorem", but I'm not sure how common that is) that the o.g.f. for words in which no pair of consecutive letters is among a restricted set is the multiplicative inverse of the o.g.f. for words in which every pair of consecutive letters is in that restricted set, evaluated at $(-a,-b,-c,\dots)$.
So for your problem, the o.g.f. for words in $a,b,c$ where all adjacent letters are the same is $$g(a,b,c) = 1 + a + b + c + a^2 + b^2 + c^2 + \cdots = 1 + \frac{a}{1-a}+\frac{b}{1-b}+\frac{c}{1-c},$$ which means the generating function for words in $a,b,c$ where no adjacent letters are the same is $$f(a,b,c) = \frac{1}{g(-a,-b,-c)} = \frac{1}{1-\frac{a}{1+a}-\frac{b}{1+b}-\frac{c}{1+c}}.$$