OK, Here is my problem:
Given an array, such as {9, 4, 3, 2, 5, 4, 3, 2}, its longest monotonous decrease subsequence is {9, 5, 4, 3, 2}, where each element is in the same order as in original array. For simplicity, we assume the elements in subsequence are all different.
I have thought about it for a whole day and can’t get a solution… If you have some good advises, please share with me. Thank you!
This is a dynamic programming problem. The idea is to evaluate every possible subsequence combination and store sub problem results in an array so you don’t need to compute them twice.
To run the code:
Running the code on your example input calculates 5. I recommend a book called the algorithm design manual for a better understanding of dynamic programming. The author is a professor and posts lectures from his algorithms online @ http://www.cs.sunysb.edu/~skiena/373/.