最长上升子序列 o(n*logn)算法
来源:互联网 发布:mac pro 无法关闭蓝牙 编辑:程序博客网 时间:2024/06/06 01:13
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<queue>
const int MOD = 1e9+7;
const int MAXN = 40050;
typedef long long LL;
using namespace std;
int num[MAXN];
int main()
{
int T, n, tmp, m;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
num[0]=0;
int len=1;
for(int i=0; i<n; i++)
{
scanf("%d",&tmp);
if(tmp>num[len-1])
num[len++]=tmp;
else
{
m=upper_bound(num,num+len,tmp)-num;
num[m]=tmp;
}
}
printf("%d\n",len-1);
}
return 0;
}
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<queue>
const int MOD = 1e9+7;
const int MAXN = 40050;
typedef long long LL;
using namespace std;
int num[MAXN];
int main()
{
int T, n, tmp, m;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
num[0]=0;
int len=1;
for(int i=0; i<n; i++)
{
scanf("%d",&tmp);
if(tmp>num[len-1])
num[len++]=tmp;
else
{
m=upper_bound(num,num+len,tmp)-num;
num[m]=tmp;
}
}
printf("%d\n",len-1);
}
return 0;
}
阅读全文
0 0
- 最长上升子序列 o(n*logn)算法
- DP之最长上升子序列O(n*logn)算法
- DP之最长上升子序列O(n*logn)算法
- HDU 1025 Constructing Roads (最长上升子序列O(n*logn)算法)
- 最长上升子序列的N*logN算法
- hdu1025 (最长上升子序列n*logn)
- 最长不下降子序列的O(n*logn)算法
- Poj 1631 n*logn 的最长上升子序列(LIS)算法
- ZOJ3627 POJ1631 HDU1950 Bridging Signals,O(N*logN)版最长上升子序列问题
- 区间 纪中 1382 最长不上升子序列o(n logn)
- UVALive-7374-Racing Gems(最长上升子序列O(n*logn))
- HOJ 2985 Wavio Sequence(最长递增子序列以及其O(n*logn)算法)
- n*logn最长上升序列
- 最长XX子序列N*LOGN算法
- 最长上升子序列之O(n^2)算法
- 杭电1257(最长递增子序列O(N*N)+O(N*logN))
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列+n*logn算法)
- 【LIS最长上升子序列】O(n^2)与O(nlogn)算法(HDU1257)
- git基本命令
- Mysql的反单引号
- Android打包出现错误:"XXX" is not translated in "af" (Afrikaans), "am" (Amharic), "ar" (Arabic).....
- 关于未来编程方式的随想
- ubuntu里装java8(亲测有效)
- 最长上升子序列 o(n*logn)算法
- 统计文件夹(包含子文件夹)中每种类型的文件及个数
- 脚本语句
- POJ 6184 【三元环 +分治】
- MySQL语句
- string和stringBuffer的区别
- STL中(queue)用法简单运用
- BeanUtils使用
- 别人的百度面试