-
Notifications
You must be signed in to change notification settings - Fork 2
Longest Increasing Subsequence (LIS)
Rafiul Islam edited this page Nov 23, 2018
·
6 revisions
-
10 2 1 3 5 4 6 9 8 1 1 1 1 1 1 1 1 1 -
-
for(int i=1; i<len; i++)
{
// check current's previous
for(int j=0; j<i; j++)
{
// if current is smaller or equal to any of previous
if(arr[j] >= arr[i])
continue;
// is current item's LIS is not less then previous value
if(ans[j]+1 <= ans[i])
continue;
// set the current item's LIS value
ans[i] = ans[j]+1;
}
}