C++ Simplified Solution Using DP | C++ | Dynamic Programming
\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        long long n=arr.size();\n        long long mod=1e9+7;\n        vector<i
```\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        long long n=arr.size();\n        long long mod=1e9+7;\n        vector<int> ans(n, 1);\n        sort(arr.begin(), arr.end());\n        long long ans1=0;\n        for(int i=0; i<n; i++){\n            int in=0, en=i;\n            int k=0;\n            while(in<i && en>=0){\n                if((long long)arr[in]*arr[en]==arr[i]){\n                    long long k=(long long)ans[in]*ans[en]; k%=mod;\n                    ans[i]+=k;\n                    ans[i]%=mod;\n                    in++; en--;\n                }\n                else if((long long)arr[in]*arr[en]>arr[i]){\n                    en--;\n                }\n                else in++;\n            } \n        }\n        for(int i=0; i<n; i++){ \n            ans1+=ans[i];\n            ans1%=mod;\n        }\n        return ans1;\n    }\n};\n```
[]