C++ code | Recursion -->> Memoization
Code\n\n\n\n\n//RECURSION - TLE at 47/49\nclass Solution {\npublic:\n    vector<int> temp;\n    void solve(int i, vector<int> &nums, vector<int> &ans){\n       
# Code\n\n\n\n```\n//RECURSION - TLE at 47/49\nclass Solution {\npublic:\n    vector<int> temp;\n    void solve(int i, vector<int> &nums, vector<int> &ans){\n        if(i >= nums.size()){\n            if(ans.size() > temp.size()){\n                temp = ans;\n                \n            }\n            return;\n            \n        }\n\n\n        if(ans.size() == 0 || nums[i] % ans.back()  == 0){\n            ans.push_back(nums[i]);\n            solve(i+1, nums, ans);\n            ans.pop_back();\n        }\n\n        solve(i+1, nums, ans);\n\n\n    }\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        vector<int> ans;\n        sort(nums.begin(), nums.end());\n        \n        solve(0, nums, ans);\n        \n        return temp;\n    }\n};\n\n\n//MEMOIZATION\n\nclass Solution {\npublic:\n    vector<int> temp;\n    void solve(int i, vector<int> &nums, vector<int> &ans, vector<int> &dp){\n        if(i >= nums.size()){\n            if(ans.size() > temp.size()){\n                temp = ans;\n                \n            }\n            return;\n            \n        }\n\n        //if at present index it satisfies modullus condition and also has greater length before then \n        //its better we consider\n        //example\n        //{3, 4, 15, 28, 32}-array after sorting\n\n        //{3, }              {}\n        //a.{3, 15} b.{3, }      c.{15, }\n        //here its just time and space waste to consider \'c\' when there is a bigger length array \'a\' with 15 included\n        //everything will be exactly same from 15 for both \'a\' , \'c\' so better to consider only \'a\' to move forward\n        if((ans.size() == 0 || nums[i] % ans.back()  == 0) && dp[i] < (int)ans.size()+1){\n            dp[i] = ans.size()+1;\n            ans.push_back(nums[i]);\n            solve(i+1, nums, ans, dp);\n            ans.pop_back();\n        }\n\n        solve(i+1, nums, ans, dp);\n\n\n    }\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        vector<int> ans;\n        sort(nums.begin(), nums.end());\n        vector<int> dp(nums.size(),-1);\n        solve(0, nums, ans, dp);\n        \n        return temp;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']