您的位置:首页 > 其它

HDU 1950最长上升子序列 学习nlogn

2017-09-19 13:56 375 查看

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1950

 本题是裸的LIS,之前和队友比赛发现自己用的dp最长上升子序列有点跟不上了,便学一发lower_bound。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[40004];
int dp[40004];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int p;
scanf("%d", &p);
for(int i = 1;i <= p;i++)
scanf("%d",&a[i]);
memset(dp, INF, sizeof(dp));
for(int i = 1;i <= p;i++)
*lower_bound(dp + 1, dp + 1 + p, a[i]) = a[i];
int ans = lower_bound(dp + 1, dp + 1 + p, INF) - (dp + 1);
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: