I have the following problem. I already solved it but I am not happy with my solution. I hope for a more slick solution and maybe somebody can help with it. Is there a way to solve this problem with just the stars/bars method?
Compute the number of ways to permute all letters from $D,D,D,O,O,O,G,G,G$ such that no two $D$ are adjacent and no two $G$ are adjacent.
My attempt.
For $k=2,3$, let $\Delta_k$ denote the set of permutations s.t. only $k$ of $D$ are adjacent, and let $\Gamma_k$ denote the set of permutations s.t. only $k$ of $G$ are adjacent. Let $U$ be the set of all permutations without any conditions.
Then $$|U|=\frac{(3+3+3)!}{3!3!3!}=1680.$$ We have $$|\Delta_3|=\frac{(1+3+3)!}{1!3!3!}=140$$ (as $\Delta_3$ is the set of permutations of $DDD,O,O,O,G,G,G$), and $$|\Delta_2|+2|\Delta_3|=\frac{(1+1+3+3)!}{1!1!3!3!}=1120$$ since this number counts the permutations of $DD,D,O,O,O,G,G,G$. Therefore $$|\Delta_2|=1120-2(140)=840.$$ Similarly $|\Gamma_3|=140$ and $|\Gamma_2|=840$.
We want to find $|\Delta_i\cap\Gamma_j|$. Since $\Delta_3\cap\Gamma_3$ is the set of permutations of $DDD,O,O,O,GGG$, $$|\Delta_3\cap\Gamma_3|=\frac{(1+3+1)!}{1!3!1!}=20.$$ Since $|\Delta_2\cap\Gamma_3|+2|\Delta_3\cap\Gamma_3|$ counts the permutations of $DD,D,O,O,O,GGG$, we have $$|\Delta_2\cap\Gamma_3|+2|\Delta_3\cap\Gamma_3|=\frac{(1+1+3+1)!}{1!1!3!1!}=120$$ so $$|\Delta_2\cap\Gamma_3|=120-2(20)=80.$$ Similarly $|\Delta_3\cap\Gamma_2|=80$.
We now want to find $|\Delta_2\cap\Gamma_2|$. Since $|\Delta_2\cap\Gamma_2|+2|\Delta_3\cap\Gamma_2|+2|\Delta_2\cap\Gamma_3|+4|\Delta_2\cap\Gamma_3|$ counts the number of permutations of $DD,D,O,O,O,GG,G$, we get $$|\Delta_2\cap\Gamma_2|+2|\Delta_3\cap\Gamma_2|+2|\Delta_2\cap\Gamma_3|+4|\Delta_2\cap\Gamma_3|=\frac{(1+1+3+1+1)!}{1!1!3!1!1!}=840.$$ Hence $$|\Delta_2\cap\Gamma_2|=840-2(80)-2(80)-4(20)=440.$$
By inclusion-exclusion principle we have $$|\Delta_2\cup\Delta_3\cup\Gamma_2\cup\Gamma_3|=\sum_{k=2}^3|\Delta_k|+\sum_{k=2}^3|\Gamma_k|-\sum_{i=2}^3\sum_{j=2}^3|\Delta_i\cap \Gamma_j|.$$ Therefore $$|\Delta_2\cup\Delta_3\cup\Gamma_2\cup\Gamma_3|=2(840)+2(140)-(440+80+80+20)=1340.$$ The question asks for the size of $U\setminus(\Delta_2\cup\Delta_3\cup\Gamma_2\cup\Gamma_3)$, which is $$|U|-|\Delta_2\cup\Delta_3\cup\Gamma_2\cup\Gamma_3|=1680-1340=340.$$
I don't know if there is a slicker way to do this but it can be simpler, even using your approach.
Permutations of "DD D G G G O O O" cover all cases of adjacent D's and adjacent G's except where G's are adjacent but D's are not.
$i)$ Permutations of "DD D G G G O O O" $= \dfrac{8!}{3!3!} - \dfrac{7!}{3!3!} = 980$
[The subtraction is to take care of adjacent DD D and D DD considered different. So DDD permutations are counted twice and need to be taken out once.]
$ $
$ii)$ Permutations of "GG G O O O" and placing $3$ D's in $3$ of the non-adjacent $6$ places
$$= \dfrac{5!}{3!}.{^6}C_3 - \dfrac{4!}{3!}.{^5}C_3 = 360$$
[The subtraction is to take care of adjacent GG G and G GG considered different. So GGG permutations and placing D in $3$ out of $5$ places have been counted twice and need to be counted out once.]
$ $
That gives you the desired arrangements $= 1680 - 980 - 360 = 340$