c++ | memoized recursive code
The readability of the code has somewhat decreased but still i will try explaning:\n1. we sort the array to reduce the extra time in the for loop for bigger num
The readability of the code has somewhat decreased but still i will try explaning:\n1. we sort the array to reduce the extra time in the for loop for bigger numbers than the number we want to find factors of. \n2. we store the elements in a set so that accesing them will be simpler.\n3. run the loop for each element and calculate the no of trees which can be formed.\n4. Jumping to the helper function.\n5. we keep the initial count as 1 , as we can form a tree of singlr node always.\n6. then iterate over the array, check if the number we are on is smaller than the number we need find factors of else we break the loop.\n7. then we check for its factors and see if they are present on the set if yes we call the helper function for the subtrees.\n8. return the total count.\n9. we use a map to memoize the code and store the results and return directly when a similar tree or subtree is formed.\n\n```\nclass Solution {\npublic:\n    int mod = 1000000007;\n    long long helper(vector<int> & arr,unordered_map<int,long long> &m,unordered_set<int> &st, int i)\n    {\n        if(m.find(i)!=m.end())\n            return m[i];\n        long long cnt =1;\n        for(auto it:  arr)\n        {\n            if(it>i)\n                break;\n            if(i%it==0 && st.find(i/it)!=st.end())\n                cnt= cnt%mod + (helper(arr,m,st,i/it)%mod)*(helper(arr,m,st,it)%mod);\n        }\n        return m[i]=cnt%mod;\n    }\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        unordered_map<int,long long> m;\n        unordered_set<int> st;\n        sort(arr.begin(),arr.end());\n        for(auto it: arr)\n            st.insert(it);\n        int ans=0;\n        for(auto it : arr)\n            ans = ans%mod + helper(arr,m,st,it)%mod;\n        return ans%mod;\n    }\n};\n```\n**THANKS  FOR READING IF YOU DID I\'M JUST TRYING TO GET BETTER AT EXPLANING THINGS.**\n![image](https://assets.leetcode.com/users/images/274ca368-21b2-4830-a9ea-d278020fdc90_1660030690.2098832.jpeg)\n
['Dynamic Programming', 'Recursion', 'Memoization']