1.定义
最长上升子序列(Longest Increasing Subsequence,LIS)是指一个序列中最长的单调递增的子序列。(
字面意思)
2.写法1(O(n^2))
这种写法主要思路是单纯动态规划
代码如下
标签:int,max,++,ans,序列,上升,最长,dp From: https://blog.csdn.net/Michael888888ha/article/details/139353519#include <iostream>
#define N 10000
using namespace std;
int a[N + 10] , dp[N + 10] , n , ans;
int main(){
cin >> n;
for(int i = 0 ; i < n ; i ++){
cin >> a[i];
}
for(int i = 0 ; i < n ; i ++){
dp[i] = 1;
for(int j = 0 ; j < i ; j ++){
if(a[j] < a[i]) //比较符号
dp[i] = max(dp[i] , dp[j] + 1);
}
ans = max(ans , dp[i]);
}