A sequence X[1..m] of integers is said to be convex if X[i+1] - X[i] > X[i] - X[i-1] for every integer i between 2 and m-1.
for (int i = 1; i < list.size(); i++) {
for (int j = 0; j < list.size(); j++) {
dp[i][j] = 2;
for (int k = 0; k < j; k++) {
if (dp[j][k] + 1 > dp[i][j] && ((list.get(i) + list.get(k)) > (list.get(j) * 2))) {
dp[i][j] = dp[j][k] + 1;
}
len = Math.max(len, dp[i][j]);
}
}
}
I have found there is a pattern that Given X[1..m], define Y[2..m] by letting Y[i] = X[i] - X[i-1]. Thus, Y is the sequence consisting of differences between successive terms of X. The sequence X is convex if and only if the sequence Y is increasing. I am wondering is there any way to get the subsequence like A = [0, 3, 7, 8, 13], then a longest convex subsequence is [0, 3, 7, 13]. Thanks in advance.
[0, 3, 7](or[7, 8, 13]for that matter), or do you want to remove all data points that would break the convexness? - luk2302