日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hiho1718(LIS)

發布時間:2024/3/12 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hiho1718(LIS) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

就是求2段下降子序列的和的最長,那正向一次LIS,反向一次LIS,然后枚舉分界點就可以了。。




/***        ┏┓    ┏┓*        ┏┛┗━━━━━━━┛┗━━━┓*        ┃       ┃  *        ┃   ━    ┃*        ┃ >   < ┃*        ┃       ┃*        ┃... ⌒ ...  ┃*        ┃       ┃*        ┗━┓   ┏━┛*          ┃   ┃ Code is far away from bug with the animal protecting          *          ┃   ┃ 神獸保佑,代碼無bug*          ┃   ┃           *          ┃   ┃       *          ┃   ┃*          ┃   ┃           *          ┃   ┗━━━┓*          ┃       ┣┓*          ┃       ┏┛*          ┗┓┓┏━┳┓┏┛*           ┃┫┫ ┃┫┫*           ┗┻┛ ┗┻┛*/ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,l,r) for(int i=l;i>=r;i--) #define link(x) for(edge *j=h[x];j;j=j->next) #define mem(a) memset(a,0,sizeof(a)) #define ll long long #define eps 1e-12 #define succ(x) (1<<x) #define lowbit(x) (x&(-x)) #define sqr(x) ((x)*(x)) #define mid (x+y>>1) #define NM 100005 #define nm 1000005 #define pi 3.1415926535897931 using namespace std; const int inf=1000000007; ll read(){ll x=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return f*x; }int n,a[NM],d[NM],c[NM],f[NM],ans,len; int main(){n=read();if(n==1)return 0*printf("1\n");dec(i,n,1)a[i]=read();d[len=1]=a[1];c[1]=1;inc(i,2,n){if(d[len]>=a[i])d[lower_bound(d,d+1+len,a[i])-d]=a[i];else d[++len]=a[i];c[i]=len;}mem(d);d[len=1]=-a[n];f[n]=1;d[0]=-inf;dec(i,n-1,1){if(d[len]>=-a[i])d[lower_bound(d,d+1+len,-a[i])-d]=-a[i];else d[++len]=-a[i];f[i]=len;}//inc(i,1,n)printf("%d ",b[i]);putchar('\n');//inc(i,1,n)printf("%d ",f[i]);putchar('\n');inc(i,1,n)ans=max(ans,c[i]+f[i+1]);return 0*printf("%d\n",ans); }



#1718 : 最長一次上升子序列

時間限制:10000ms 單點時限:1000ms 內存限制:256MB

描述

給定一個由N個元素組成的序列: A1, A2, ... AN,請你找出其中最長的子序列B1, B2, ... BM滿足其中至多有一次上升,即只有一次Bi+1 - Bi > 0。

輸入

第一行包含一個整數N。 ?

第二行包含N個兩輛不同的整數,A1, A2, ... AN。 ?

對于30%的數據,1 <= N <= 1000 ?

對于100%的數據,1 <= N <= 100000 , 1 <= Ai <= 100000

輸出

最長的滿足條件的序列的長度

樣例輸入
5 3 5 4 1 2
樣例輸出
4

總結

以上是生活随笔為你收集整理的hiho1718(LIS)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。