It was over 20 years since I studied maths and I am stuck. I'd really appreciate some help understanding this (probably quite simple) problem.
I have $n$ items that I can place on $m$ positions. $m$ ≥ $n$. The total number of combinations is the old and trusty ${m \choose n}$, but I also need to partition the combinations on k - the number of items directly adjacent to each other
What I am looking for is best shown with a couple of examples.
Five positions and four items can be combined in two ways when $k$ is four, two ways when $k$ is three and one way when $k$ is two
.
Five positions and three items can be combined in three ways when $k$ is three, six ways when $k$ is two and one way when $k$ is one.

Five positions and one item can be combined in five ways when $k$ is one.

What I am trying to find is a function $f(m, n, k)$ that give me the number of combinations for some value $k$. For example:
$f(5, 3, 3)$ => $3$
$f(5, 3, 2)$ => $6$
$f(5, 3, 1)$ => $1$
Of course, adding up the number of combinations for all valid $k$ is ${m \choose n}$.
Just by toying with pen and paper I have observed some edge cases
$f(x, x, x)$ => $1$
$f(x, 1, 1)$ => $x$
$f(x, y, y)$ => $x-y+1$
Help me, please!
There is no simple formula, but you can use a simple recursive property to efficiently compute $f$.
Border conditions :
if $k>n$ or $n>m$ then $f(m,n,k)=0$
if $k=m=n$ then $f(m,n,k)=1$
Then, any valid (m,n,k) configurations either :
$$f(m,n,k)=\sum_{i=0}^kf(m-i-1,n-i,k)+\sum_{i=0}^{k-1}f(m-k-1,n-k,i)$$
Using that, you can very efficiently compute $f$ with some dynamic programming. An example in python :
And then compute $f(300,60,8) = 3093843836691461760481283005507531400353771346949728892427692$ in a few seconds.