Permutations with restriction 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.
 A: Here is a generating function for the problem.  I will do the case where there are three types of object, but the pattern will be evident.  The strategy is to represent the free associative algebra on the types of object modulo the relation that each generator squares to zero.
Define 
$$x = \pmatrix{
 0 & 0 & 0 \\
 1 & 0 & 0 \\
 1 & 0 & 0
}
$$
$$y = \pmatrix{
 0 & 1 & 0 \\
 0 & 0 & 0 \\
 0 & 1 & 0
}
$$
$$z = \pmatrix{
 0 & 0 & 1 \\
 0 & 0 & 1 \\
 0 & 0 & 0
}
$$
Now we build the generating function:
$$f_k(a,b,c) = \pmatrix{1/2 & 1/2 & 1/2} (ax + by + cz)^k \pmatrix{1 \\ 1 \\ 1}.$$
For example, 
$$f_4(a,b,c)=2a^2b^2 + 6a^2bc + 6ab^2c + 2a^2c^2 + 6abc^2 + 2b^2c^2.$$
These coefficients are the answers to the problem.  For instance, the first term asserts that there are exactly two ways to use $a,a,b,b$ to form a string without adjacent $a$'s or $b$'s.
If you care to diagonalize the matrix in the middle, you can obtain a more explicit formula for $f$.
A: 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}}.$$
