using dp to get max sequence in a sorted array