51nod动态规化--最长单调递增子序列

来源:互联网 发布:中科大软件学院本科 编辑:程序博客网 时间:2024/05/05 08:01

题目:

给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)

例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。
输入

第1行:1个数N,N为序列的长度(2 <= N <= 50000)第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)

输出

输出最长递增子序列的长度。

输入示例

8516824510

输出示例

5

代码如下:

#include <bits/stdc++.h>using namespace std;typedef long long LL;const int INF = 0x7fffffff;const int maxn = 50000 + 131;int Dp[maxn], Num[maxn];int main() {    int N;    while(cin >> N) {        for(int i = 0; i < N; ++i) cin >> Num[i];        fill(Dp, Dp+N, INF);        for(int i = 0; i < N; ++i) {//            d=lower_bound(Dp, Dp+N, Num[i])-Dp;//            printf("%d\n",);*lower_bound(Dp, Dp+N, Num[i]) = Num[i];                    }        cout << lower_bound(Dp, Dp+N, INF) - Dp << endl;    }}
#include<bits/stdc++.h>这个头文件包含以下等等C++中包含的所有头文件: 

#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 

等等……

不过在国内oj中,poj,hdu 不支持这个函数,这几个oj的编译器问题,其他国外的oj,还有台湾的oj都支持,CF,Topcoder也都支持。




0 0
原创粉丝点击