human
Longest increasing subsequence consisting of elements from indices divisible by previously selected indices | Function to find length of longest subsequence generated that satisfies the specified conditions.
Stores the length of longest subsequences of all lengths.
Iterate through the given array.
Iterate through the multiples i.
Update dp [ j ] as maximum of dp [ j ] and dp [ i ] + 1.
Return the maximum element in dp [ ] as the length of longest subsequence.
Driver Code.
Function Call"
How can the above be solved in Python?
 ... Give me a code to longest increasing subsequence consisting of elements from indices divisible by previously selected indices and the other steps required?
assistant
#Here is code to longest increasing subsequence consisting of elements from indices divisible by previously selected indices and the other steps required.
 def findMaxLength ( N , arr ) :
	dp = [ 1 ] * ( N + 1 )
	for i in range ( 1 , N + 1 ) :
		for j in range ( 2 * i , N + 1 , i ) :
			if ( arr [ i - 1 ] < arr [ j - 1 ] ) :
				dp [ j ] = max ( dp [ j ] , dp [ i ] + 1 )
	return max ( dp )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
	N = len ( arr )
	print ( findMaxLength ( N , arr ) )