最长上升子序列(快速)

最长上升子序列和找有多少个递减的其实是一个事情;
如8 4 2 5 3 9 1 6 7这个序列,找最长上升子序列,
以下代码的过程就是,8 4 2 1都在N[0]那里变化,5 3在N[1]那里变化
9 6在N[2]那里变化 7在N[3]那里变化,所以最后的数组是1 3 6 7,长度为4;

#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
#define MAX 0x3f3f3f3f
int N[100005];
int main()
{
	int n, t;
	cin >> n;
	memset(N, MAX, sizeof(N));
	for (int i = 0; i < n; i++)
	{
		int m;
		cin >> m;   //lower是找数组内第一个大于等于m的那个数的地址,减去
		t = lower_bound(N, N + n, m) - N;//首地址就是那个i了;
		N[t] = m;
	}
	cout << lower_bound(N, N + n, MAX) - N;
	return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值