博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aizu - DPL_1_D Longest Increasing Subsequence dp+二分查找 最长递增子序列
阅读量:3904 次
发布时间:2019-05-23

本文共 816 字,大约阅读时间需要 2 分钟。

For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.

An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.

Input

na0a1:an-1

In the first line, an integer n is given. In the next n lines, elements of A are given.

Output

The length of the longest increasing subsequence of A.

Constraints

  • 1 ≤ n ≤ 100000
  • 0 ≤ ai ≤ 109

Sample Input 1

551324

Sample Output 1

3

 

Sample Input 2

3111

Sample Output 2

1

n^2复杂度的算法过不了此题。。。

需要dp+二分过。。。

代码如下:

#include 
#include
#include
#include
using namespace std;const int maxn=100005;int n;int a[maxn];int dp[maxn];int Max;void init(){ Max=1; dp[0]=a[0];}int main(){ scanf("%d",&n); for (int i=0;i

 

转载地址:http://jxaen.baihongyu.com/

你可能感兴趣的文章
PTA卡片邻居游戏JAVA版——山东科技大学
查看>>
欢迎使用CSDN-markdown编辑器
查看>>
Java与C++的析构函数
查看>>
终结Android项目的R文件报错问题
查看>>
模仿Toast实现提示框
查看>>
Bitmap优化
查看>>
Android: Bitmap与DrawAble与byte[]与InputStream之间的转换
查看>>
java-设计模式-创建模式-建造者模式builder
查看>>
java-设计模式-创建模式-工厂模式factory
查看>>
java-设计模式-创建模式-观察者模式observer
查看>>
原子性、可见性以及有序性
查看>>
Session的生命周期
查看>>
死锁实例
查看>>
生产者消费者实例
查看>>
java中数组定义String a[]和String[] a有什么区别?
查看>>
Java权限访问修饰符 亲测总结
查看>>
Jsp与servlet的区别
查看>>
struct spring hibernate辨析
查看>>
Spring和SpringMVC的区别
查看>>
java程序与操作系统API的关系
查看>>