Question
For $d, n \in \mathbb{N}$ define $$ f(d, n) = \frac{1}{d^n} \sum_{r=1}^d \sum_{m=r}^d (-1)^{m+r}rm {d \choose m}{m \choose r} (r-1)^{n-1}. $$
For a given $d$, what $n$ maximizes $f(d,n)$?
Context
This is the expectation for the following game. Throw $n$ dice (each having $d$ faces). You get as many points as there are different values appearing. Except if two adjacent dice (the dice are in a row) have the same value, in which case you get $0$ points for that throw.
Examples:
- 1, 5, 2, 4, 1 $\space \space \mapsto$ $4$ points (4 different values: 1,2,4,5)
- 6, 2, 2, 4, 3 $\space \space \mapsto$ $0$ points (because 2's next to each other)
- 2, 6, 1, 2, 6 $\space \space \mapsto$ $3$ points (3 different values: 1,2,6)
The formula $f$ for this expectation can be derived by inclusion-exclusion in a similar fashion that the number of surjections is calculated, we just have some more factors in there.
Remarks
The maximizing $n$ seems to grow linearly and be about $n_{max} = 0.69d -0.42$. And the quantity $f(d, n_{max})$ also looks linear with a coefficient $0.12$.
Can this be proved and how about the exact value of these coefficients?

We derive a closed formula for $f(d,n)$ which will considerably ease maximum calculations. We show the following is valid for natural numbers $n,d\geq 1$: \begin{align*} \color{blue}{f(d,n)} &\color{blue}{=\frac{1}{d^n}\sum_{r=1}^d\sum_{m=r}^d(-1)^{m+r}rm\binom{d}{m}\binom{m}{r}(r-1)^{n-1}}\\ &\,\,\color{blue}{=(1-d)\left(1-\frac{2}{d}\right)^{n-1}+d\left(1-\frac{1}{d}\right)^{n-1}}\tag{1} \end{align*}
In the following we use the coefficient of operator $[z^n]$ to denote the coefficient of $z^n$ of a series. This way we can write for instance \begin{align*} r^{n}=n![z^n]e^{rz}\tag{2} \end{align*}
Comment: In (3) we change the order of summation according to \begin{align*} \sum_{r=1}^d\sum_{m=r}^d a_{rm}=\sum_{1\leq r\leq m\leq d} a_{rm}=\sum_{m=1}^d\sum_{r=1}^m a_{rm} \end{align*} and we use the binomial identity $\binom{p}{q}=\frac{p}{q}\binom{p-1}{q-1}$.
Comment:
In (4.1) we use again the binomial identity $\binom{p}{q}=\frac{p}{q}\binom{p-1}{q-1}$.
In (4.2) we shift the index by one to start with $r=0$.
In (4.3) we use (2) and apply in the lines below after some rearrangements the binomial theorem.
Comment:
In (5.1) we shift the index $m$ to start with $m=0$.
In (5.2) we get rid of the factor $m+1$ by using the differential operator $\frac{d}{dz}$.
In (5.3) we do some rearrangements to be able to apply the binomial theorem again.
In (5.4) we use the coefficient of operator as indicated in (2).