human
Print all Longest dividing subsequence in an Array | Function to print LDS [ i ] element.
Traverse the Max [ ].
Function to construct and print Longest Dividing Subsequence.
2D vector for storing sequences.
Push the first element to LDS [ ] [ ].
Interate over all element.
Loop for every index till i.
If current elements divides arr [ i ] and length is greater than the previous index , then insert the current element to the sequences LDS [ i ].
L [ i ] ends with arr [ i ].
LDS stores the sequences till each element of arr [ ] Traverse the LDS [ ] [ ] to find the maximum length.
Print all LDS with maximum length.
Find size.
If size = maxLength.
Print LDS.
Driver Code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to print all Longest dividing subsequence in an Array and the other steps required.
 def printLDS ( Max ) :
	for it in Max :
		print ( it , end = " ▁ " )
def LongestDividingSeq ( arr , N ) :
	LDS = [ [ ] for i in range ( N ) ]
	LDS [ 0 ] . append ( arr [ 0 ] )
	for i in range ( 1 , N ) :
		for j in range ( i ) :
			if ( ( arr [ i ] % arr [ j ] == 0 ) and ( len ( LDS [ i ] ) < len ( LDS [ j ] ) + 1 ) ) :
				LDS [ i ] = LDS [ j ] . copy ( )
		LDS [ i ] . append ( arr [ i ] )
	maxLength = 0
	for i in range ( N ) :
		x = len ( LDS [ i ] )
		maxLength = max ( maxLength , x )
	for i in range ( N ) :
		size = len ( LDS [ i ] )
		if ( size == maxLength ) :
			printLDS ( LDS [ i ] )
			print ( )
arr = [ 2 , 11 , 16 , 12 , 36 , 60 , 71 ]
N = len ( arr )
LongestDividingSeq ( arr , N ) ;