We have a sequence. What is the smallest number should be removed to sequence be a growing array?
Example: 5 1 2 4 3 6 4 6
If left sequence 1 2 4 6 then we kicked four numbers.
And if you leave the series 1 2 3 4 6 then we threw three the number of which is better than four.
So answer is 3. Can anyone have any idea how to solve by DP? Sorry for bad English.
What you need to do is to find longest increasing subsequence. If its length is K and length of array is N then the answer is N - K.
Dynamic programming: dp[i] = the longest increasing subsequence ending in i-th element.
So dp[i] = {maximum for all j: 0 <= j < i and a[j] < a[i]} (dp[j] + 1)
So basically
We can improve solution to O(NlogM), where M = length of LIS. Here it was discussed.
My code in C++