SEABUB - Editorial

D = sum of previous DP row( DP[J][Q-1] * prob[N][J]). The next row depends only on D, because from the point we start shuffling again(e.g. 3 at 2nd iteration in above case): the optimal answer is just D(the previous DP row sum) - like in above case it is 1/6*1.5 = 0.25 => D = 1.5.