improved longest inc subsequence algorithm