DFS: traversing all permutations and all operations
\n# Code\n\nclass Solution {\npublic:\n    vector<float> ops(float a, float b)\n    {\n        return {a+b,a-b,b-a,a*b,a/b,b/a};\n    }\n    bool dfs(vector<int
\n# Code\n```\nclass Solution {\npublic:\n    vector<float> ops(float a, float b)\n    {\n        return {a+b,a-b,b-a,a*b,a/b,b/a};\n    }\n    bool dfs(vector<int> nums, int k, float res)\n    {\n        if (k==3)\n        {\n            for (float f:ops(res,nums[3]))\n                if (fabs(f-24.0)<0.001) return true;\n            return false;\n        }\n        else if (k==1)\n        {\n            for (float f:ops(nums[0],nums[1]))\n                if (dfs(nums,2,f)) return true;\n            return false;\n        }\n        //k==2\n        for (float f:ops(res,nums[2]))\n            if (dfs(nums,3,f)) return true;\n        for (float f:ops(nums[2],nums[3]))\n            for(float g:ops(res,f))\n                if (fabs(g-24)<0.001) return true;\n        return false;\n    }\n    bool judgePoint24(vector<int>& cards) {\n        for (int i=0;i<4;i++){\n            for (int j=0;j<4;j++){\n                if (j==i) continue;\n                for (int k=0;k<4;k++){\n                    if (k==i || k==j) continue;\n                    for (int m=0;m<4;m++){\n                        if (m==i || m==j || m==k) continue;\n                        vector<int> v={cards[i],cards[j],cards[k],cards[m]};\n                        if (dfs(v,1,0)) return true;\n                    }\n                }\n            }\n            \n        }\n        return false;\n    }\n};\n```
['C++']