Longest Increasing Subsequence
程序员文章站
2022-06-06 15:50:56
...
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int s[n+1];
for(int i=1;i<=n;i++){
cin>>s[i];
}
int dp[n+1];//定义dp[i]为以a[i]结尾的最长上升子序列
for(int i=1;i<=n;i++){
dp[i]=1;//最小为1
}
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++){
if(s[j]<s[i]){
dp[i]=max(dp[j]+1,dp[i]);
}
}
}
int max=1;
for(int i=1;i<=n;i++){
if(dp[i]>max) max=dp[i];
}
cout<<max;
return 0;
}
/*
Points:
最长上升子序列
定义dp[i]为以a[i]结尾的最长上升子序列
*/
下一篇: windows安装python虚拟环境
推荐阅读
-
14. Longest Common Prefix 最长公共前缀
-
Leetcode-14 Longest Common Prefix
-
NO14. Longest Common Prefix (Easy) (Java)
-
USACO-Section2.3 Longest Prefix【动态规划】
-
mysql Sort aborted: Out of sort memory, consider increasing server sort buffer s
-
最长上升子序列(LIS: Longest Increasing Subsequence)
-
SPOJ1811 LCS - Longest Common Substring(后缀自动机)
-
Longest Substring Without Repeating Characters
-
LeetCode - 3.Longest Substring Without Repeating Characters(388ms)
-
The Xor-longest Path(trie树)