题目大意
给定长度为 n 的序列 A,求其最长严格上升子序列(LIS)的长度。
AC代码
该题目实际上是要求最长上升子序列严格递增
AC https://www.luogu.com.cn/record/183531657
实际上我这题做法是O(n^2)的,不能通过下面这题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <iostream> using namespace std; typedef long long ll; const ll N=5010;
ll n,dp[N],A[N],ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;++i) { cin>>A[i]; } for(int i=1;i<=n;++i) { dp[i]=1; } for(ll i=n-1;i>=1;--i) { for(ll j=n;j>=i+1;--j) { if(A[i]<A[j]) { dp[i]=max(dp[i],1+dp[j]); } } } for(int i=1;i<=n;i++) { ans=max(ans,dp[i]); } cout<<ans<<endl; return 0; }
|
心路历程(WA,TLE,MLE……)