nlogn 的最长上升子序列

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[100000];
int a[100000];
int b[100000];
int main()
{
int i = 0;
while (cin >> a[i])i++;
for (int x = 0;x < i;x++)b[x] = a[i - x - 1];
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, b[j]) = b[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp<<endl;
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, a[j]) = a[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp;
system("pause");

return 0;


这里最后要说明一下,使用lower_bound函数求出的序列是严格最长上升序列,也就是说对于每一项i>j 都满足a[i]>a[j],

而使用的是upper_bound的话就可以取等号,在导弹拦截那道题中,第一问是可以取等号的,而第二问是不可以的,这里一定要注意

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值