✔️ C++ || DP + Map || Easy-Understanding
\nclass Solution\n{\n    public:\n        const int mod = 1e9 + 7;\n    int numFactoredBinaryTrees(vector<int> &arr)\n    {\n        vector < long long > dp(arr
````\nclass Solution\n{\n    public:\n        const int mod = 1e9 + 7;\n    int numFactoredBinaryTrees(vector<int> &arr)\n    {\n        vector < long long > dp(arr.size(), 1);\n        unordered_map<int, int> mp;\n        sort(arr.begin(), arr.end());\n        \n        for (int i = 0; i < arr.size(); i++)\n        {\n            mp[arr[i]] = i;//store the index of various elements of the array\n            for (int j = i - 1; j >= 0; j--)\n            {\n                if (arr[i] % arr[j] == 0)//to check whether arr[j] is a factor of arr[i] or not\n                {\n                    int temp = arr[i] / arr[j];\n                    if (mp.count(temp)) dp[i] += (dp[j] *dp[mp[temp]]) % mod;//check the presence of the required no in map, If it is in the map then increase dp[i] by the product of the dp[j] and dp[mp[temp]] taking the modulus\n                }\n            }\n        }\n        \n        long long ans = 0;\n        ans = accumulate(dp.begin(), dp.end(), 0LL);\n        return ans%mod;//return toatl sum after taking modulus\n    }\n};\n````
['Dynamic Programming', 'C']