Classical DP - Similar to Longest Increasing Subsequence (LIS)
\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        vector <int> dp(nums.
```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        vector <int> dp(nums.size(), 1);\n        int maxLen = 1;\n        for (int i=0; i<nums.size(); i++) {\n            for (int j=0; j<i; j++) {\n                if (nums[i] % nums[j] == 0)\n                    dp[i] = max(dp[i], dp[j] + 1);\n            }\n            maxLen = max(maxLen, dp[i]);\n        }\n        vector <int> ans;\n        int prev = -1;\n        for (int i=nums.size() - 1; i>=0; i--) {\n            if (maxLen == dp[i] && (prev == -1 || prev % nums[i] == 0)) {\n                ans.emplace_back(nums[i]);\n                maxLen--;\n                prev = nums[i];\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']