🏆C++ || DP + Sliding Window
Code\n\nclass Solution {\npublic:\n    double new21Game(int n, int k, int mp) {\n        if(k==0 || n>k+mp)return 1;\n       vector<double>dp(n+1,0.0);\n       
# Code\n```\nclass Solution {\npublic:\n    double new21Game(int n, int k, int mp) {\n        if(k==0 || n>k+mp)return 1;\n       vector<double>dp(n+1,0.0);\n       dp[0]=1;\n       double ans=0.0;\n       double ps=1;\n       for(int i=1;i<=n;i++){\n           dp[i] = ps/mp;\n           if(i<k)ps += dp[i];\n           else ans += ps/mp;\n           if(i-mp>=0)ps -= dp[i-mp];\n       }\n       return ans;\n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/a68e80ec-6e15-42b0-a5dd-da9e537ad5c4_1685001882.9615173.jpeg)\n
['C++']