We arrange $N$ boys and $M$ girls in a row. In how many ways can we get a maximal sequence of $K$ boys OR $K$ girls?

137 Views Asked by At

We arrange $N$ boys and $M$ girls in a row with importance of order (thus, we have $(N+M)!$ permutations for that arrangement). In how many ways can we get a maximal sequence of $K$ boys OR $K$ girls (or both)?

For example, here we have an arrangement of $N=4$ boys and $M=5$ girls with a maximal sequence of $K=3$ :

$$GGBGGBBBG$$ Of course we could have a sequence of 3 girls AND 3 boys in other row, that counts too.

EDIT: People told me that my interpretation for "maximal sequence" wasn't clear enough, so let me be more precise: I am looking for the Probability that there is at least one sequence of $K$ boys OR $K$ girls OR both - AND no sequence bigger than K. $$$$

I tried everything but (apparently) I always get duplications in my counting. I coded a python code which calculates exactly that, just for testing, and none of my trials worked (my answers was always bigger).

I'd really appreciate your help!

My attempt was: $\frac{{N\choose K}(N+M-K+1)!K!+{M\choose K}(N+M-K+1)!K!}{(N+M)!}$

where ${N\choose K}$ for choosing $K$ boys, $(N+M-K+1)!$ for putting everyone in line while relating the $K$ chosen-boys as one, then $K!$ for all of their permutations(the K-chosen-boys). Same thing for the girls. Devide all that with $(N+M)!$.

1

There are 1 best solutions below

0
On

In this answer it is calculated that the bivariate generating function for the binary words that contain runs (of either symbol) of length at most $k$ is

$$G_k(u,w) = \frac{\frac{1-u^{k+1}}{1-u} \frac{1-w^{k+1}}{1-w}}{1 - u\frac{1-u^{k}}{1-u}w\frac{1-w^{k}}{1-w}}. $$

Notice that now $G_k(u,w)-G_{k-1}(u,w)$ enumerates the words with maximal run equal to $k$ i.e. we subtract the number of words where the maximal run is at most $k-1$.

I include here a SageMath script that does calculation

def f(n,m,k):
    R.<u,w> = PowerSeriesRing(QQ, 2)
    prec = n+m+1 #upto what order we need
    H = lambda z, kk: (1-z^kk)/(1-z).O(prec) #helper
    G = H(u,k+1) * H(w,k+1) / (1-u*H(u,k)*w*H(w,k)).O(prec) - H(u,k) * H(w,k) / (1-u*H(u,k-1)*w*H(w,k-1)).O(prec)
    return G.coefficients()[u^n*w^m]


print (f(5,4,3))

This gives the answer as the number of binary words. If you want the order among the boys and among the girls to matter as you do, multiply the answer by $m!n!$.