题目
给定一个序列A及它的长度n(长度小于等于500),请返回LIS的长度
分析
这是一个经典的LIS(即最长上升子序列)问题,可以利用动态规划的思想解决
private static int getLIS(int[] A, int n) {
// write code here
int[] dp = new int[n];
int max = 0;
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (A[j] < A[i] && dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
}
}
if (max < dp[i]) {
max = dp[i];
}
}
return max;
}