Longest increasing subsequence problem in Scala.