I have a set of integers. I want to find the longest increasing subsequence of that set using dynamic programming.
This can be solved in O(n^2) using Dynamic Programming. Python code for the same would be like:-
def LIS(numlist):
LS = [1]
for i in range(1, len(numlist)):
LS.append(1)
for j in range(0, i):
if numlist[i] > numlist[j] and LS[i]<=LS[j]:
LS[i] = 1 + LS[j]
print LS
return max(LS)
numlist = map(int, raw_input().split(' '))
print LIS(numlist)
For input:5 19 5 81 50 28 29 1 83 23
output would be:[1, 2, 1, 3, 3, 3, 4, 1, 5, 3]
5
The list_index of output list is the list_index of input list. The value at a given list_index in output list denotes the Longest increasing subsequence length for that list_index.