[C++] O(n^2) solution || 97% Faster Approach
```\nclass Solution {\npublic:\n    vector largestDivisibleSubset(vector& nums) {\n        vectordp(nums.size(),1);\n        sort(nums.begin(),nums.end());\n   
```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        vector<int>dp(nums.size(),1);\n        sort(nums.begin(),nums.end());\n        for(int i=1;i<nums.size();i++){\n            for(int j=0;j<i;j++){\n                if(nums[i]%nums[j]==0) dp[i]=max(dp[i],1+dp[j]);\n            }\n        }\n        int val=0;\n        for(int i=0;i<dp.size();i++) if(val<dp[i]) val=dp[i];\n        vector<int>v;\n        for(int i=dp.size()-1;i>-1;i--){\n            if(val==dp[i] and (!v.size() or v[v.size()-1]%nums[i]==0)){\n                v.push_back(nums[i]);\n                val--;\n            }\n        }\n        return v;\n    }\n};
['Dynamic Programming', 'C']