Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Longest Increasing Subsequence Dynamic programming
- # R@1313I
- # Function that returns the Number of Longest Increasing Subsequence
- def lonIncreSub(arr):
- n = len(arr)
- # Set All the value to 1
- lis = [1] * n
- # Compare the current value with previous all the value and increase the lis count if current v is greater than previous v
- for i in range(1, n):
- for j in range(0, i):
- if arr[i] > arr[j] and lis[i] < lis[j] + 1:
- lis[i] = lis[j] + 1
- # Set the max number to 0
- maximum = 0
- # FInd the maximum of all LIS values
- for i in range(n):
- maximum = max(maximum, lis[i])
- return maximum
- arr = list(map(int, input("Enter Some Subsequence Number: ").split()))
- print("Longest Subsequence Number in the list is: ", lonIncreSub(arr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement