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.
Process the input elements in order and maintain a list of tuples for each element. Each tuple (A,B), for the element i will denotes, A = length of longest increasing sub-sequence ending at i and B = index of predecessor of list[i] in the longest increasing sub-sequence ending at list[i].
Start from element 1, the list of tuple for element 1 will be [(1,0)] for element i, scan the list 0..i and find element list[k] such that list[k] < list[i], the value of A for element i, Ai will be Ak + 1 and Bi will be k. If there are multiple such elements, add them to the list of tuples for element i.
In the end, find all the elements with max value of A (length of LIS ending at element) and backtrack using the tuples to get the list.
I have shared the code for same at http://www.edufyme.com/code/?id=66f041e16a60928b05a7e228a89c3799