public class AscendingSequence {
public static void main(String[] args) {
int[] a = new int[]{
10, 2, 2, 5, 1, 7, 101, 18
};
System.out.println(Ascend(a));
}
static public int Ascend(int[] a) {
int[] dp = new int[a.length];
int max = dp[0] = 1;
for (int i = 0; i < dp.length; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (a[i] > a[j]) {
continue;
}
dp[i] = Math.max(dp[i], dp[j] + 1);
}
max = Math.max(dp[i], max);
}
return max;
}
}
最长上升子序列(动态规划)
最新推荐文章于 2021-01-06 16:49:06 发布