human
What is a code to printing Maximum Sum Increasing Subsequence and the other steps required given the following:
Printing Maximum Sum Increasing Subsequence | Utility function to calculate sum of all vector elements.
Function to construct Maximum Sum Increasing Subsequence.
L [ i ] - The Maximum Sum Increasing Subsequence that ends with arr [ i ].
L [ 0 ] is equal to arr [ 0 ].
start from index 1.
for every j less than i.
L [ i ] = { MaxSum ( L [ j ] ) } + arr [ i ] where j < i and arr [ j ] < arr [ i ].
L [ i ] ends with arr [ i ].
L [ i ] now stores Maximum Sum Increasing Subsequence of arr [ 0. . i ] that ends with arr [ i ].
.
find max.
max will contain result.
Driver Code.
construct and prMax Sum IS of arr"
How can the above be solved in Python?
assistant
#Here is code to printing Maximum Sum Increasing Subsequence and the other steps required.
 def findSum ( arr ) :
	summ = 0
	for i in arr :
		summ += i
	return summ
def printMaxSumIS ( arr , n ) :
	L = [ [ ] for i in range ( n ) ]
	L [ 0 ] . append ( arr [ 0 ] )
	for i in range ( 1 , n ) :
		for j in range ( i ) :
			if ( ( arr [ i ] > arr [ j ] ) and ( findSum ( L [ i ] ) < findSum ( L [ j ] ) ) ) :
				for e in L [ j ] :
					if e not in L [ i ] :
						L [ i ] . append ( e )
		L [ i ] . append ( arr [ i ] )
	res = L [ 0 ]
/ * res = L [ 0 ] ; * /
	for x in L :
		if ( findSum ( x ) > findSum ( res ) ) :
			res = x
	for i in res :
		print ( i , end = " ▁ " )
arr = [ 3 , 2 , 6 , 4 , 5 , 1 ]
n = len ( arr )
printMaxSumIS ( arr , n )