Solution
C++ []\nclass Solution {\npublic:\n    double new21Game(int n, int k, int mx) {\n        if (k == 0 || n >= k + mx) return 1.0;\n        vector<double> dp(n+1);
```C++ []\nclass Solution {\npublic:\n    double new21Game(int n, int k, int mx) {\n        if (k == 0 || n >= k + mx) return 1.0;\n        vector<double> dp(n+1);\n        dp[0] = 1.0;\n        double pref = 1.0;\n        double res = 0.0; \n        for (int i = 1; i <= n; i++){\n            dp[i] = pref / mx;\n            if (i < k) pref += dp[i];\n            if (i >= mx && i < k + mx) pref -= dp[i - mx];\n            if (i >= k) res += dp[i];\n        }\n        return res;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def new21Game(self, n: int, k: int, maxPts: int) -> float:\n        dp = [1.0] + [0] * n\n        Wsum = 1.0\n        if k == 0 or n >= k + maxPts:\n            return 1\n        for i in range(1, n+1):\n            dp[i] = Wsum/maxPts\n            if i < k:\n                Wsum += dp[i]\n            if i >= maxPts:\n                Wsum -= dp[i-maxPts]\n        return sum(dp[k:])\n```\n\n```Java []\nclass Solution {\n    public double new21Game(int n, int k, int maxPts) {\n        if(n>=k+maxPts-1){\n            return 1;\n        }\n        double[] dp =new double[k+maxPts];\n        double p=1/(maxPts+0.0);\n        dp[0]=1;\n        double prev =0;\n        for(int i=1;i<=k;i++){\n            prev = prev -(i-maxPts-1>=0?dp[i-maxPts-1]:0)+dp[i-1];\n            dp[i]=prev*p;\n        }\n        double res = dp[k];\n        for(int i=k+1;i<=n;i++){\n            prev = prev -(i-maxPts-1>=0?dp[i-maxPts-1]:0);\n            dp[i]=prev*p;\n            res+=dp[i];\n        }\n        return res;\n    }\n}\n```\n
['C++', 'Java', 'Python3']