Can someone explain why counting number of ways to get to X approach doesn't give correct answer??
I understand it\'s not efficient and sufferes from extreme complexity. BUT I was wondering if someone can tell me why I don\'t get the correct answer for Exampl
I understand it\'s not efficient and sufferes from extreme complexity. **BUT I was wondering if someone can tell me why I don\'t get the correct answer for Example-3 using this approach???**\n\nYour answer 0.55218,    Expected Output: 0.73278\n\nways[X] shows the number of ways to get to X points\ntotal: total number of ways to get to >= K points\n\nSo the answer should be Sum of (1) and (2):\n\n1) Probability of getting X points (ways[X]/total) * (ways to go from X to between K and N, which is equal to (N-K+1))\nAdd these for X from N-W to K-1.\n\n2) Probability of getting X points (ways[X]/total) * (Ways to go between K and less than N)\nAdd these for X from K-W to N-W-1.\n\n\n\n\n```\nclass Solution {\npublic:\n    double new21Game(int N, int K, int W) {\n        // N=21; K=17; W=10;\n        ways.assign(N+W, 0);\n        if (N-K >= W-1) return 1;\n        total = 0;\n        \n        countWays(0, K, W);\n        double res=0.0, tmp=0.0;\n        for (int i=K-1; i>= K-W+1 && i >=0 && i >= N-W; i--) {\n            tmp += ((1.0*ways[i])/total) * ((double)N-K+1);\n        }\n        for (int i=N-W-1; i>= K-W && i >=0; i--) {\n            tmp += ((1.0*ways[i])/total) * ((double)i+W-K+1);\n        }\n        return tmp;\n    }\n    \n    void countWays(int cur, int K, int W) {\n        ways[cur]++;\n        if (cur >= K) {\n            total++;\n            return;\n        }\n        for (int i=1; i<=W; i++) {\n            countWays(cur+i, K, W);\n        }\n    }\n    vector<int> ways;\n    int total;\n};\n\n```
[]