dp[i][0] denotes the index of last element of MAX -ve(1st diff is -ve)
sub sequence ending at i
dp[i][2] denotes the length of this sub sequence
dp[i][1] denotes the index of last element of MAX +ve(1st diff is -ve)
sub sequence ending at i
d[[i][3] denotes the length of this sub sequence

-initialize dp[i][0] and d[[i][0] as i
-initialize dp[i][2] and dp[i][3] as 1 for all i=1 to n

1. dp[i][0] = MAX(len +1,dp[i][2]) for all j<i and

(a[i]> prev element) XOR (len +1 MOD 2)
where prev = a[dp[j][0]]  and len = dp[j][2] //a[i] can be added to
sequence


2. dp[i][1] = MAX(len+1,dp[i][3]) for all j<i and

(a[i]< prev) XOR (len +1 MOD 2)
where prev = a[dp[j][1]]  and len = dp[j][3] //a[i] can be added to
sequence

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to