Addendum added to respond to a comment-request for a closed form formula for $~f(k,n).$
This is not an answer.
Instead this is merely a comment that describes an alternative approach.
Stars and Bars provides a (somewhat ugly) alternative approach. See this answer as a model of how to compute the enumeration factors discussed later in this response.
There are $8$ different ways of partitioning $7$, so that none of the terms are greater than $3$. These are
3-3-1, 3-2-2, 3-2-1-1, 3-1-1-1-1
2-2-2-1, 2-2-1-1-1, 2-1-1-1-1-1, 1-1-1-1-1-1-1-1.
For each such (mutually exclusive) partitioning, you would need to take the product of a scaling factor times a enumeration factor.
Then, you would sum the $8$ products together.
For example, the 3-2-1-1 has a scaling factor of $4 \times 3 = 12,$ since there are $4$ choices for the position of the $3,$ and then $3$ choices for the position of the $2.$
Further, consider the following tableau:
- DDD - DD - D - D -
There are $5$ islands created by this partitioning. Reading the islands left to right, let $x_1, \cdots, x_5$ denote the size of these islands. The islands represent the potential locations of the $9$ R's.
Let $k$ denote the number of these islands. So, in this situation, $~k = 5.$
Then, the enumeration factor will be the number of solutions to
$x_1 + \cdots + x_k = 9.$
$x_1, \cdots, x_k \in \Bbb{Z_{\geq 0}}$.
$x_1, \cdots, x_k \leq 3.~$
$x_2, \cdots, x_{k-1} \geq 1.$
The last bullet point above is used to preserve the integrity of the 3-2-1-1 structure. The corresponding enumeration factor is computed following the model, linked near the start of this response.
The last bullet point disrupts the symmetry that might otherwise be found in computing the enumeration factor, so the math does get messy.
This is why I am providing a long-winded comment, rather than a complete answer. It is because the math gets messy.
$\underline{\text{Addendum}}$
Per request, providing a closed form formula for $~f(k,n),~$ which corresponds to the enumeration of the following:
$x_1 + \cdots + x_k = n.$
$x_1, \cdots, x_k \in \Bbb{Z_{\geq 0}}.$
$x_1, \cdots, x_k \leq 3.~$
$x_2, \cdots, x_{k-1} \geq 1.$
To simplify the formula, I am going to adopt the convention that $~\displaystyle \binom{a}{b} = 0,~$ whenever $~a < b.$
The first step is to eliminate the last bullet point above, through the change of variables : $~y_i = x_i - 1 ~: ~i \in \{2,\cdots,k-1\}.$
This changes the enumeration problem to :
$x_1 + y_2 + \cdots + y_{k-1} + x_k = n - (k-2) = n + 2 - k.$
$x_1, y_2, \cdots, y_{k-1}, x_k \in \Bbb{Z_{\geq 0}}.$
$x_1, x_k \leq 3.~$
$y_2, \cdots, y_{k-1} \leq 2.$
The enumeration will be expressed as
$$\sum_{r=0}^k (-1)^r T_r.$$
Then,
$$T_0 = \binom{[n + 2 - k] + [k-1]}{k-1} = \binom{n+1}{k-1}.$$
Then, there are $~2~$ choices for the $~x_1~$ or $~x_k~$ variable being the sole violation, and $~k-2~$ choices for one of the remaining variables being in violation. So,
$$T_1 = \left[ ~2 \times \binom{n-3}{k-1} ~\right] + \left[ ~(k-2) \times \binom{n-2}{k-1} ~\right].$$
To compute $~T_r ~: ~r \in \{2,3,\cdots,k\},~$ you have to distinguish $~3~$ mutually exclusive cases, depending on how many of the variables $~\{x_1,x_k\}~$ are included in the $~r~$ variables in violation.
Let
$T_r(0)~$ denote that none of $~\{x_1,x_k\}~$ are included.
$T_r(1)~$ denote that one of $~\{x_1,x_k\}~$ is included.
$T_r(2)~$ denote that both of $~\{x_1,x_k\}~$ are included.
Then, you have that
$$T_r = T_r(0) + T_r(1) + T_r(2),$$
where,
$$T_r(0) = \binom{k-2}{r} \times \binom{2}{0} \times \binom{n+1 - 3r}{k-1}.$$
$$T_r(1) = \binom{k-2}{r-1} \times \binom{2}{1} \times \binom{n+1 - 3r - 1}{k-1}.$$
$$T_r(2) = \binom{k-2}{r-2} \times \binom{2}{2} \times \binom{n+1 - 3r - 2}{k-1}.$$