public List<Integer> largestDivisibleSubset(int[] nums) {
        List<Integer> result = new ArrayList<Integer>();
		
        if (nums == null || nums.length == 0) {
        	return result;
        }
        
        Arrays.sort(nums);
        
        int[] dp = new int[nums.length], index = new int[nums.length];
        dp[0] = 1;
        index[0] = -1;
        
        int max = 1, end = 0;
        
        for (int i = 1; i < nums.length; i++) {
        	for (int j = 0; j < i; j++) {
        		if (nums[i] % nums[j] == 0 && dp[j] + 1 > dp[i]) {
    				dp[i] = dp[j] + 1;
    				index[i] = j;
        		}
        	}
        	
        	if (max < dp[i]) {
				max = dp[i];
				end = i;
			}
        }
        
        while (end >= 0) {
        	result.add(nums[end]);
        	end = index[end];
        }
        
        return result;
	}