Given $N$ Identical Red balls and $M$ Identical Black balls, in how many ways we can arrange them such that not more than $K$ adjacent balls are of same color.
Example : For $1$ Red ball and $1$ black ball, with $K=1$, there are $2$ ways $[RB,BR]$
Can there be a general formula for given $N$,$M$ and $K$ ?
I have read about Dutch flag problem to find number of ways to find such that no adjacent balls are of same color. I am bit stuck on how to find for at max K balls.