Why would this brute-force solution give wrong answer on small inputs
I was trying to build my solution starting from brute-force and then optimizing it. Hence, I wrote the brute force code below. However, it doesn\'t work on the 
I was trying to build my solution starting from brute-force and then optimizing it. Hence, I wrote the brute force code below. However, it doesn\'t work on the third test case mentioned in the question description that is ,\nN = 21, K =17 and W = 10.\nCan anyone please help me analyze it.\nP.S : I know its a bad solution, and I also know it has to be solved using DP. But, I generally have a habit to first formulate a brute-force to identify the repeated recursion and then formulate the DP formula.\n\n```\nclass Solution {\npublic:\n    void util(vector<int>& visited,int N,int K,int W,double& num,double& den,int sum){\n        if(sum >= K){\n            if(sum <= N)\n                num++;\n            den++;\n            return;\n        }\n        \n        for(int i = 1;i <= W;i++){\n            if(!visited[i]){\n                sum += i;\n                visited[i] = 1;\n                util(visited,N,K,W,num,den,sum);\n                sum -= i;\n                visited[i] = 0;\n            }\n        }\n    }\n    \n    double new21Game(int N, int K, int W) {\n        double den = 0,num = 0;\n        int sum = 0;\n        vector<int> visited(W+1,0);\n        util(visited,N,K,W,num,den,sum);\n        return (den != 0 ? num/den : 0);\n    }\n};\n```
[]