No, it's correct. If so, I would get the answer of 0.0 because even the very first step would be made from net profit >=1, but at the start we have only net profit of 0 available.
Ok, here is the math formula behind that code. I will use "i, j, k" for indices and "mm, kk, ll" for input values to stay synched with code variables.
a, b, c - number of wheel positions ( out of 28 ) where each symbol appears once, twice and three times respectively (this was discussed above). a=4, b=2, c=2.
v(i) - power of bet amount, i=0..nv-1
v(i) = 2^i.
2^(nv-1) <= ll, nv -> max
f(i, j, k) - probability of the state
i - number of rounds played (0 - played nothing, 1 - after 1st round)
j - bet index at this step (0..nv-1), actually Sten will bet for 2^j.
k - his overall profit. That is, what would be his ballance delta since the game begining if he leaves Ex at this point.
For i<kk (i.e. for rounds when we don't care what is our profit), all states are propagated to 4 possible further states:
To f(i+1, (j+1)%nv, k-v[j]) with probability of f(i, j, k) * (28-a-b-c) / 28 // loss
To f(i+1, 0, k+v[j]) with probability of f(i, j, k) * a / 28 // win bet
To f(i+1, 0, k+v[j]*2) with probability of f(i, j, k) * b / 28. // win bet x 2
To f(i+1, 0, k+v[j]*3) with probability of f(i, j, k) * c / 28. // win bet x 3
So, as you may see, nothing is lost during processing i=0..kk-1. Sum(j=0..nv-1, k=-100..100) == 1.0 for any 0 <= i < kk.
Once i >= kk, we can propagate only states with positive net profit, i.e. states with k >= 1. You may see this in code as:
for(k = i<kk ? -BASE : 1 ; k<BASE ; k++)
Take a look at the initialization expression. If current 'i' (number of rounds was played) is less then 'kk', then we start at -INF, otherwise we start at 1. For sample input BASE is large enough to work as INF for us.
Also, in the end we amass only values >= 1.
The only difference in code from this statement is that array 'f' is shifted BASE elements on its 3rd argument to keep that index positive.
To be the best you must become the best!