Let $W(p,q,r,s)$ be the number of permutations of the letters which satisfy the following conditions : 


**Condition 1** : The letters are consist of $P,Q,R,S$.


**Condition 2** : The number of letter $P,Q,R,S$ is $p,q,r,s$ respectively.


**Condition 3** : Any two adjacent letters are different from each other.


**Condition 4** : The first letter is $P$, and the last letter is **not** $P$.


Then, here is my question.



> 
> **Question** : Can we get a closed-form expression of $W(p,q,r,s)$ for $p\ge 2$?
> 
> 
> 


**Remark** : This question has been [asked previously on math.SE](https://math.stackexchange.com/questions/573269/permutations-of-letters-under-some-conditions) without receiving any answers.


**Motivation** : I've just got the following closed-form expression of $W(1,q,r,s)$ : 


$W(1,q,r,s)=$
$$\sum\_{k=1}^{q+1}\binom{r-1}{k-1}\left\{\binom{q-1}{k}\binom{2k}{q-1+r-s}+2\binom{q}{k}\binom{2k}{q+r-s}+\binom{q+1}{k}\binom{2k}{q+1+r-s}\right\}$$


However, I'm facing difficulty for the $p\ge 2$ cases. Can anyone help?



Permutations of letters under some conditions
Let $W\_P(p,q,r,s)$ be the number of such words starting by $P$ and *ending* by $P$, and let 
$$
 f\_P(x,y,z,t)=\sum\_{p,q,r,s}W\_P(p,q,r,s)x^py^qz^rt^s.
$$
Define $f\_Q$, $f\_R$, $f\_S$ similarly (all words start by $P$!). Then
$$
 \pmatrix{f\_P\\f\_Q\\f\_R\\f\_S}
 =
 \pmatrix{0&x&x&x\\y&0&y&y\\z&z&0&z\\t&t&t&0}\pmatrix{f\_P\\f\_Q\\f\_R\\f\_S}
 +\pmatrix{x\\0\\0\\0},
$$
which implies
$$
 \pmatrix{f\_P\\f\_Q\\f\_R\\f\_S}
 =\pmatrix{1&-x&-x&-x\\-y&1&-y&-y\\-z&-z&1&-z\\-t&-t&-t&1}^{-1}\pmatrix{x\\0\\0\\0}.
$$
Thus the generating function for your $W(p,q,r,s)$ is
$$
 f(x,y,z,t)=\pmatrix{0&1&1&1}\pmatrix{1&-x&-x&-x\\-y&1&-y&-y\\-z&-z&1&-z\\-t&-t&-t&1}^{-1}\pmatrix{x\\0\\0\\0},
$$
which, accorging to Maple, is
$$
 f(x,y,z,t)=\frac{x(y+z+t+2yz+2yt+2zt+3yzt)}{1-xy-xz-xt-yz-yt-zt-2xyz-2xyt-2xzt-2yzt-3xyzt}.
$$
I doubt there is a much closer form. But you may find the expressions like yours in particular cases from here.


