C++ || Easy Solution
\n# Code\n\nclass Solution {\nprivate:\n    long long solve(vector<int> &arr, int i, unordered_map<int,int> &mp, vector<int> &dp){\n        if(i < 0)\n         
\n# Code\n```\nclass Solution {\nprivate:\n    long long solve(vector<int> &arr, int i, unordered_map<int,int> &mp, vector<int> &dp){\n        if(i < 0)\n            return 0;\n        \n        if(dp[i] != -1)\n            return dp[i];\n\n        long long ans = 1;\n        for(int j = 0; j < i; j++){\n            if(arr[i] % arr[j] == 0 && mp.find(arr[i] / arr[j]) != mp.end()){\n                long long left = solve(arr, j, mp, dp);\n                long long right = solve(arr, mp[arr[i]/arr[j]], mp, dp);\n                ans = (ans + (left*right) % mod) % mod;\n            }\n        }\n        return dp[i] = ans;\n    }\npublic:\n    long long mod = 1e9 + 7;\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        sort(arr.begin(), arr.end());\n        unordered_map<int,int> mp;\n        for(int i = 0; i < arr.size(); i++)\n            mp[arr[i]] = i;\n        \n        int res = 0;\n        for(int i = arr.size() - 1; i >= 0; i--){\n            vector<int> dp(arr.size() + 1, -1);\n            res = (res + (int)solve(arr, i, mp, dp)) % mod;\n        }\n        return res;\n    }\n};\n```\n![upvote_leetcode.jpeg](https://assets.leetcode.com/users/images/4f8ea6d1-6553-4d89-9d7d-f70d0bf13eae_1698296109.1532962.jpeg)\n
['Memoization', 'C++']