题意:最长上升子序列nlogn写法
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int dp[1005]; 7 int a[1005]; 8 int main(){ 9 int n; 10 while(cin>>n){ 11 for(int i=0;i<n;i++){ 12 cin>>a[i]; 13 } 14 memset(dp,0,sizeof(dp)); 15 dp[1]=a[0]; 16 int flag=1; 17 for(int i=1;i<n;i++){ 18 int temp=lower_bound(dp,dp+flag,a[i])-dp; 19 if(dp[flag]<a[i]){ 20 dp[++flag]=a[i]; 21 } 22 else if(a[i]<dp[temp]){ 23 dp[temp]=a[i]; 24 } 25 } 26 cout<<flag<<endl; 27 } 28 return 0; 29 }
原文地址:https://www.cnblogs.com/ttttttttrx/p/10261395.html
时间: 2024-10-06 15:28:18