#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 4000;
int main() {
int n, number[MAXN], dp[MAXN]; //dp[i]表示(强制)以A[i]结尾的最长不下降子序列的长度
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&number[i]);
}
//状态转移方程
int maxNumber = -1;
for(int i=0; i<n; i++) {
dp[i] = 1; //边界
for(int j=0; j<i; j++) {
if(number[j] <= number[i] && dp[j] + 1 > dp[i])
dp[i] = dp[j] + 1;
}
maxNumber = max(maxNumber, dp[i]);
}
//输出
printf("%d\n",maxNumber);
return 0;
}
DP-最长不下降子序列 LIS
最新推荐文章于 2024-03-26 17:46:43 发布