本文共 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.
na0a1:an-1
In the first line, an integer n is given. In the next n lines, elements of A are given.
The length of the longest increasing subsequence of A.
551324
3
3111
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/