最長先上公升後下降子串行 登山

2022-05-04 01:57:10 字數 465 閱讀 5223

給定乙個長度為\(n\)的序列\(a\),求最長的乙個子串行,這個序列先上公升後下降

\(1\leq n\leq 1000\)

分別求出每個點從前往後的最長上公升子串行和最長下降子串行,去所有點這兩個點去除重複點後的最大值

#includeusing namespace std;

#define rep(i,a,n) for(int i=a;i=a;i--)

#define ll long long

const int n=1010;

int n,f[n],f[n],a[n];

int main()

per(i,1,n+1)

int ans=-1;

rep(i,1,n+1)

ans=max(ans,f[i]+f[i]-1);

printf("%d\n",ans);

}

最長上公升子串行,最長不下降子串行

最長上公升子串行 include includeusing namespace std const int n 23333 12 int dp n a n int n int binarysearch int k,int len else if k dp mid else mid l r 1 ret...

最長上公升子串行 和 最長不下降子串行

最長上公升子串行 是嚴格上公升的,alower bound 返回序列中大於等於key值的第乙個數 比如說序列 1 2 3 4 5,key值為3,使用lower bound返回第三個數 最長不下降子串行 不是嚴格上公升,可以存在多個數相等的情況,用upper bound upper bound 返回序...

最長上公升 不下降子串行

最長上公升 不下降子串行 lis 有兩種方法 1.動態規劃,o n 2 容易得出o n 2 的dp遞推公式 d i max 1 1 j d i 為以元素i結尾的最長子序列個數。這樣經過兩重迴圈一次遍歷可以得到最長上公升子串行。view code 1 include 2 include 3 inclu...