G - Yet Another RGB Sequence Editorial by shadow9
A formula for finding the number of strings obtained by arranging \(K\) K
’s, \((R-K)\) R
’s, \((G-K)\) G
’s, and \(B\) B
’s, that does not contain a substring RG
can be derieved.
First arrange R
, RG
and B
. There are \(\frac{(b + k + r-k)!}{(r-k)!b!k!}\) ways of doing so. Now all the G
’s must be filled in the gaps. We can’t fill in G
afterR
because then they will make RG
. So the number of spots where we can fill in G
’s are \(((r-k) + b + k + 1 - (r-k)) = b + k + 1\). So the final answer can be given by the formula,
\(\frac{(b + k + r-k)!}{(r-k)!b!k!} \cdot \binom{(g-k) + spots - 1}{g-k}\)
Where \(spots = b + k + 1\).
posted:
last update: