Suppose $cnt(i)$ represents the number of occurrences of $i$ in array $A$ of length $n$ whose elements are between $1$ and $n$. An array is called a $k$-good array if and only if $cnt(k)=k$ and $\forall i\not=k, cnt(i)\not=i$. Let $f(n,k)$ be the number of all $k$-good arrays of length $n$ whose elements are between $1$ and $n$.
For example, $4,2,3,3,3$ is a $k$-good array for $n=5,k=3$, but $2,2,3,3,3$ is not a $k$-good array for $n=5,k=3$, because $cnt(2)$ also equals to $2$ so you can't tell from what $k$ the array is derived.
I am wondering if there is a recursive formula for $f(n,k)$.