### Background

$\newcommand\ms[1]{\mathsf #1}\def\msP{\ms P}\def\msS{\ms S}\def\mfS{\mathfrak S}$Suppose I have $n$ marbles of $c$ colors, where $c≤n$. Let $n_i$ denote the number of marbles of color $i$.

Let $\msP=(1^{n_1} 2^{n_2} \dots c^{n_c})$ be the multiset $\small\{\underbrace{1, \dots, 1}_{n_1},\underbrace{2,\dots,2}_{n_2},\dots,\underbrace{c,\dots,c}_{n_c}\}$ in frequency representation.

The number of distinct permutations of $\msP$ is given by the multinomial: $$\left|\mfS_{\msP}\right|=\binom{n}{n_1,n_2,\dots,n_c}=\frac{n!}{n_1!\,n_2!\cdots n_c!}=n! \prod_{i=1}^c \frac1{n_i!}.$$

### Question

How many permutations of $\msP$ have a run of length *k*?

Let $r_k(\msS)$ be true if a permutation $\msS$ has a run of length $k$ ($k$ marbles in a row are the same color).

For example, if I have 5 marbles (2 green, 2 blue, and 1 yellow), then:

- If $\msS$ is
`GBYGB`

, then $r_1(\msS)$ is true, but $r_2(\msS)$ is false.- If $\msS$ is
`GBBYG`

or`GGBBY`

, then $r_1(\msS)$ and $r_2(\msS)$ are true, but $r_3(\msS)$ is false.Let the number of permutations of $\msP$ having a run of length $k$ be $$N(k; \msP)=\sum\limits_{\msS\in\mfS_\msP}[r_k(\msS)]$$ where $[x]$ denotes the Iverson bracket.

Is there a formula for $N(k; \msP)$?

Essentially, I would like to find a generalization of this recurrence for the case $c=2$ (Bloom 1996).

### What I have done so far

I constructed the table below, counting the permutations for configurations of up to $n=7$ marbles by brute force. The rightmost columns count the permutations having runs of length $2≤k≤n$.

Unfortunately, brute force stops being practical around $n\gtrsim 11$ (at $10^8$ permutations; see A005651).

Here is a closer look at the permutations comprising the five $n=4$ cases.

I tried to find patterns along different axes that would lead me to formulas for those specific cases, which I could then generalize, but I haven’t gotten anywhere. I then tried deriving a recurrence relation, also to no avail. My hunch, however, is that there may be a Fibonacci-like recurrence relation involved.

### Update

I have entered Andrew’s solution into Mathematica:

```
Ν[r_, P_] := Multinomial@@P - c[r, P]
c[r_, P_] := CoefficientRules[Π[r, P, t]] /. ({a_} -> b_) :> b a! // Total
Π[r_, P_, t_] := Product[q[r, ni, t], {ni, P}]
a[x_, r_, t_] := a[x, r, t] = Exp[t (x - x^r)/(1 - x^r)]
q[r_, n_, t_] := q[r, n, t] = SeriesCoefficient[a[x, r, t], {x, 0, n}]
```

The values up to $n=5$ match the tables above:

```
Column@Table[
Grid@Table[
Table[Ν[r, partition], {r, 1, Max[partition]}
], {partition, IntegerPartitions[marbles]}
], {marbles, 1, 5}
]
1
1 1
2
1 1 1
3 2
6
1 1 1 1
4 4 2
6 4
12 6
24
1 1 1 1 1
5 5 4 2
10 9 3
20 18 6
30 18
60 24
120
```

### Table of $q_{r,n}(t)$ polynomials

$$\newcommand\f[1]{\color{gray}{#1}} \begin{array}{r|llllll} r \backslash n & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 2 & \f{t} & \frac{t^2}{2}-t & \frac{t^3}{6}-t^2+t & \frac{t^4}{24}-\frac{t^3}{2}+\frac{3 t^2}{2}-t & \frac{t^5}{120}-\frac{t^4}{6}+t^3-2 t^2+t & \frac{t^6}{720}-\frac{t^5}{24}+\frac{5 t^4}{12}-\frac{5t^3}{3}+\frac{5 t^2}{2}-t \\ 3 & \f{t} & \f{\frac{t^2}{2}} & \frac{t^3}{6}-t & \frac{t^4}{24}-t^2+t & \frac{t^5}{120}-\frac{t^3}{2}+t^2 & \frac{t^6}{720}-\frac{t^4}{6}+\frac{t^3}{2}+\frac{t^2}{2}-t \\ 4 & \f{t} & \f{\frac{t^2}{2}} & \f{\frac{t^3}{6}} & \frac{t^4}{24}-t & \frac{t^5}{120}-t^2+t & \frac{t^6}{720}-\frac{t^3}{2}+t^2 \\ 5 & \f{t} & \f{\frac{t^2}{2}} & \f{\frac{t^3}{6}} & \f{\frac{t^4}{24}} & \frac{t^5}{120}-t & \frac{t^6}{720}-t^2+t \\ 6 & \f{t} & \f{\frac{t^2}{2}} & \f{\frac{t^3}{6}} & \f{\frac{t^4}{24}} & \f{\frac{t^5}{120}} & \frac{t^6}{720}-t \\ \end{array} $$