Iam_Sandeep

Maximum sum increasing subsequence

May 2nd, 2022 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. #User function Template for python3
  2. class Solution:
  3.     def maxSumIS(self, A, n):
  4. '''Inititalization here its important'''
  5.         arr=[i for i in A]
  6.         for i in range(n-1,-1,-1):
  7.             for j in range(i+1,n):
  8.                 if A[i]<A[j]:
  9.                     arr[i]=max(arr[i],A[i]+arr[j])
  10.         return max(arr)
  11.                
Add Comment
Please, Sign In to add comment