I am trying to create a recursive function which works with an increasing array of variables. Since the formula is quite complex, i will try to simplify my example to the core of my problem.
The initial value of the array should be $f[\{1\}]=2$ and all other arrays with a single element should have the value $0$.
When an array of size $n$ is given to the function, it will reduce the size of the array to $n-1$ by dropping the first element. So if an array with the values $\{0,0,1,0,2\}$ is given, it will reduce it to $\{0,1,0,2\}$, or more generally the array $\{r_5 ,r_4 ,r_3 ,r_2 ,r_1\}$ will be reduced to $\{r_4 ,r_3 ,r_2 ,r_1\}$. The computation in this case should be: $$f[\{r_5 ,r_4 ,r_3 ,r_2 ,r_1\}]=(r_4 -1)*f[\{r_4 -1,r_3 ,r_2 ,r_1\}]+(r_3 -1)*f[\{r_4 ,r_3 -1,r_2 ,r_1\}]+(r_2 -1)*f[\{r_4 ,r_3 ,r_2 -1,r_1\}]+(r_1 -1)*f[\{r_4 ,r_3 ,r_2 ,r_1-1\}]$$
To speed up the computation, the function should memorize results and arrays containing a negative element ($-1$) should not be computed and instead given the value 0.
My attempt so far starts with:
f[r_] := f[r] = With[{n = Length[r], k = Rest[r]}
...
To change the values of the $r_i$, I generated a For-Loop (from $1$ to $n$) containing:
f[ReplacePart[k, -i -> Part[k, -i] - 1]]
Any help is highly appreciated.