[C++] Recursion + Memoziation
\t\t#define ll long long int\n\t\tclass Solution {\n\t\tpublic:\n\t\t\tunordered_set s;\n\t\t\tunordered_map t;\n\t\t\tll m = 1000000000+7;\n\t\t\tll f(int a,ve
\t\t#define ll long long int\n\t\tclass Solution {\n\t\tpublic:\n\t\t\tunordered_set<ll> s;\n\t\t\tunordered_map<ll,ll> t;\n\t\t\tll m = 1000000000+7;\n\t\t\tll f(int a,vector<int>& arr){\n\t\t\t\tif(s.find(a)==s.end())return 0;\n\t\t\t\tif(t.find(a)!=t.end())return t[a];\n\n\t\t\t\tll cnt=1;\n\t\t\t\tfor(int i=0; i<arr.size(); i++){\n\t\t\t\t\t//cheak if arr[i] factors are present or not\n\t\t\t\t\tif(a%arr[i]==0 and s.find(a/arr[i])!=s.end()){\n\t\t\t\t\t\t// then recursively call their factor also\n\t\t\t\t\t\tcnt += (f(arr[i],arr)%m * f(a/arr[i],arr)%m)%m;\n\t\t\t\t\t\t// cnt = (cnt+k);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn t[a] = cnt;\n\t\t\t}\n\t\t\tint numFactoredBinaryTrees(vector<int>& arr) {\n\t\t\t\ts.clear();\n\t\t\t\tint n = arr.size();\n\t\t\t\tll res = 0;\n\t\t\t\tfor(auto i: arr){\n\t\t\t\t\ts.insert(i);\n\t\t\t\t}\n\t\t\t\tfor(int i=0; i<n; i++){\n\t\t\t\t\t//make it as root\n\t\t\t\t\tres += f(arr[i],arr);\n\t\t\t\t}\n\t\t\t\treturn res%m;\n\t\t\t}\n\t\t};
['Recursion', 'Memoization']