Python dp n^2 solution
We first do some math work.  For two numbers, A and B, if A < B, A % B  must > 0 (A != 0).  The only chance A % B == 0 must be A >= B.\n\nWith this idea, we sor
We first do some math work.  For two numbers, A and B, if A < B, A % B  must > 0 (A != 0).  The only chance A % B == 0 must be A >= B.\n\nWith this idea, we sort the list.  Then, the question turns similar to no.300 longest increasing subsequence.  For ith number, its largest divisible subset is the max of subset of any j from 0 - i-1 in which nums[i] % nums[j] == 0.\n\n    class Solution(object):\n        def largestDivisibleSubset(self, nums):\n            """\n            :type nums: List[int]\n            :rtype: List[int]\n            """\n            from copy import copy\n            nums.sort()\n            n = len(nums)\n            if n == 0: return []\n            dp = [0] * n\n            dp[0] = [nums[0]]\n            #print(dp)\n            for i in xrange(1, n):\n                curNum = nums[i]\n                maxSet = []\n                for j in xrange(i):\n                    if curNum % nums[j] == 0:\n                        localSet = copy(dp[j])\n                        if len(localSet) > len(maxSet):\n                            maxSet = localSet\n                \n                maxSet.append(nums[i])\n                dp[i] = maxSet\n                #print(dp)\n            \n            #print(dp)\n            res = []\n            for localSet in dp:\n                if len(localSet) > len(res):\n                    res = localSet\n            return res
['Dynamic Programming']