DP + bipartite -> LIS

DP + bipartite -> LIS

Realization of ideas

If dp [l-1] <a [i], it is connected to the back, otherwise, put a [i] dp off the top of the first greater than or equal to its number, followed by the number to ensure a greater range.

Code

#include<iostream>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int dp[maxn];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=a[0];
	int l=1;
	for(int i=1;i<n;i++)
	{
		if(dp[l-1]<a[i]) dp[l++]=a[i];
		else *lower_bound(dp,dp+l,a[i])=a[i];
	}
	cout<<l<<endl;
	return 0;
}
Published 173 original articles · won praise 6 · views 40000 +

Guess you like

Origin blog.csdn.net/shidonghang/article/details/103451390