<doocs>0368.Largest Divisible Subset_1.py
def largestDivisibleSubset( nums: List[int]) -> List[int]:
    nums.sort()
    n = len(nums)
    f, p = [0] * n, [0] * n
    for i in range(n):
        l, pre = 1, i
        for j in range(n):
            if nums[i] % nums[j] == 0 and f[j] + 1 > l:
                l = f[j] + 1
                pre = j
        f[i] = l
        p[i] = pre
    max_len, max_index = 0, 0
    for i, v in enumerate(f):
        if max_len < v:
            max_len = v
            max_index = i
    ans = []
    while len(ans) < max_len:
        ans.append(nums[max_index])
        max_index = p[max_index]
    return ans[::-1]
def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] :
    var_0.sort ( )
    var_5 = len ( var_0 )
    var_7 , var_8 = [ 0 ] * var_5 , [ 0 ] * var_5
    for var_10 in range ( var_5 ) :
        var_12 , var_13 = 1 , var_10
        for var_14 in range ( var_5 ) :
            if var_0 [ var_10 ] % var_0 [ var_14 ] == 0 and var_7 [ var_14 ] + 1 > var_12 :
                var_12 = var_7 [ var_14 ] + 1
                var_13 = var_14
        var_7 [ var_10 ] = var_12
        var_8 [ var_10 ] = var_13
    var_15 , var_16 = 0 , 0
    for var_10 , var_18 in enumerate ( var_7 ) :
        if var_15 < var_18 :
            var_15 = var_18
            var_16 = var_10
    var_19 = [ ]
    while len ( var_19 ) < var_15 :
        var_19.append ( var_0 [ var_16 ] )
        var_16 = var_8 [ var_16 ]
    return var_19 [ : : - 1 ]
