My attempt at making sense
\n\t  i)  [1...,w] is the range the value that can be drawn in a single draw\n\t  ii) the game stops as soon as sum of all values drawn becomes k or more.\n\t  
1.   \n\t  i)  [1...,w] is the range the value that can be drawn in a single draw\n\t  ii) the game stops as soon as **sum** of all values drawn becomes k or more.\n\t  iii) the goal is to find the probability that the **sum** is n or less at the end of the game. Let\'s call it sol(n).\n2.   The game does not stop until the sum is atleast k. It\'s not possible for sum to be less than k at the end of the game. If n<k then  sol(n)=0\n3.    The maximum sum at the end of the game can be (k-1)+w. This is because the maximum sum that can be reached without ending the game is k-1. Having reached this point you can make only another draw and pick a maxium of w in that draw.\n4.    if n> (k-1)+w then sol(n)=1\n5.    The range of values at the end of the game is [k,..,k-1+w]\n6.    sol(n)= P(k)+P(k+1)+...+P(n) , where P(x)= probability of the sum at the end of the game being x.\n7.   useful math formula:  If probability of event x is px and probability of event y is py, then probility of x happening after y is py * px.\n8.    Probability of sum=0 at the begining of the game is 1\n9.    Probability of sum=1 after any draw is probability of sum=0 prior to the draw multiplied by probability of picking 1 in the current draw\n10.  \n\tprob(x)= probability of sum being x after current draw \n\tc(x) = probability of drawing x in current draw\n\tprob(0)=1\n\tprob(1) = prob(0) * c(1)\n\tprob(2)= prob(1) * c(1) + prob(0) * c(2)\n\tprob(3) = prob(2) * c(1) + prob(1) * c(2) + prob(0) * c(3)\n11.  c(x) = probability of drawing x in current draw = 1/w   \n12.  prob(3) = ( prob(2) + prob(1) + prob(0) )/w\n13. prob(x) = ( prob(xMaxPriorSum)+....+ prob(xMinPriorSum) )/w, max sum prior to current draw = xMaxPriorSum , min sum prior to current draw = xMinPriorSum to make the new sum x\n14. Generally xMaxPriorSum  will increase with x and xMinPriorSum will remain zero\n15. Because of the constraints in the problem the above will not be the case\n16. xMaxPriorSum will not grow beyond k-1. If  xMaxPriorSum had been k , the game would have ended\n17. Since the maxium value you can get from the current draw is w,  xMinPriorSum=x-w   \n18. dp[i] = probability that sum after current draw would be x. \n19.  w=4, k=3, n=7\n\t\t dp[0]=prob(0)\n\t\t dp[1]= prob(0) * c(1)\n\t\t dp[2] = prob(1) * c(1) + prob(0) * c(2)  , dp[x] = prob(xMaxPriorSum) * c(x-xMaxPriorSum)+ ..... + prob(xMinPriorSum) * c(x-MinPriorSum)\n\t\t dp[3] = prob(2) * c(1) + prob(1) * c(2) + prob(0) * c(3)\n\t\t dp[4] = prob(2) * c(2) + prob(1) * c(3) + prob(0) * c(4)    , notice that xMaxPriorSum did not increase with x as x=k-1\n\t\t dp[5] = prob(2) * c(3) + prob(1) * c(4)    ,xMinPriorSum increased as current draw value can\'t exceed 4\n\t\t dp[6] = prob(2) * c(4)\n\t\t dp[7] = 0\n20. dp[7] is not our sol(7). The sol(n) = sum(dp[3],..,dp[7])\n21. Remember c(x) = 1/w for all value of x. Therefore, the value of dp[x] can be derived from the value of dp[x-1]\n22.   w=4, k=3, n=7\n\t\t dp[0]=1\n\t\t dp[1]= prob(0) /w\n\t\t dp[2] = (prob(1)  + prob(0))/w   , dp[x] = (prob(xMaxPriorSum)+ ... + prob(xMinPriorSum) )/w\n\t\t dp[3] = (prob(2)  + prob(1)  + prob(0)) /w \n\t\t dp[4] = (prob(2)  + prob(1)  + prob(0))/w     , notice that xMaxPriorSum did not increase with x as x=k-1\n\t\t dp[5] = (prob(2)  + prob(1) )/w    ,xMinPriorSum increased as current draw value can\'t exceed 4\n\t\t dp[6] = prob(2) /w\n\t\t dp[7] = 0\n23. For each x the value of xMaxPriorSum and xMinPriorSum has to be adjusted if necessary and the  value of  (  prob(xMaxPriorSum)+....+ prob(xMinPriorSum) )  has to be dtermined. Lets call it dpSum. dpSum is then divied by w to get dp[x]\n25. remember (  prob(xMaxPriorSum)+....+ prob(xMinPriorSum) ) = dpSum . It\'s a variable, it changes with x.  \n24. By leveraging dynamic programming dp[x] can be determined by the following way:\n\t\tadd dp[x-1] to the dpSum if x<k\n\t\tif x >= w, subtract dp[x-w] from dpSum\n        dp[x] = dpSum/w\n\nThe code can be found here: https://leetcode.com/problems/new-21-game/discuss/132334/One-Pass-DP-O(N)\t\t \n\t\t \n\t \n\t
[]