C++ Easy to Understand Dynamic programming (Recursive memoized TLE solution also included)
DP\n\nclass Solution {\npublic:\n    double new21Game(int N, int K, int W) {\n        vector<double> dp(N+1,0);dp[0]=1;\n        double sum=0;\n        for(int 
DP\n```\nclass Solution {\npublic:\n    double new21Game(int N, int K, int W) {\n        vector<double> dp(N+1,0);dp[0]=1;\n        double sum=0;\n        for(int i=1;i<=N;i++)\n        {\n            if(i-1<K)\n                sum+=dp[i-1];\n            if(i-W-1>=0)\n                sum-=dp[i-W-1];\n            dp[i]=(double)(sum*((double)1.0/W));\n        }\n        double ans=0;\n        for(int i=0;i<=N;i++)\n        {\n            if(i>=K)\n                ans+=dp[i];\n        }\n        return ans;\n    }\n};\n```\nThis version gives TLE\n```\nclass Solution {\npublic:int n;\n    vector<double> dp;\n    double solve(int sum,int k,int W)\n    {\n        if(sum>=k)\n        {\n            if(sum<=n)\n                return 1.0;\n            else\n                return 0.0;\n        }\n        if(dp[sum]!=-1)return dp[sum];\n        double x=0;\n        for(int i=1;i<=W;i++)\n        {\n            if(sum+i>=k and sum+i>n)break;\n            x+=(double)1/W * solve(sum+i,k,W);\n        }\n        return dp[sum]=x;\n    }\n    double new21Game(int N, int K, int W) {\n        n=N;\n        dp=vector<double>(K,-1);\n        return solve(0,K,W);\n    }\n};\n   \n   ```
[]