您的位置:首页 > 其它

九度 1533 最长上升子序列

2014-05-06 12:21 169 查看
/*
* LIS.cpp
*
*  Created on: 2014-5-6
*      Author: wangzhu
*/

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define NMAX 100001
int num[NMAX], arr[NMAX];
bool cmp(int a, int b) {
return a < b;
}
int main() {
//    freopen("data.in", "r", stdin);
int t, j, len;
while (~scanf("%d", &t)) {
for (int i = 0; i < t; i++) {
scanf("%d", num + i);
}
len = 0;
for (int i = 0; i < t; i++) {
//查找当前数组中的数在上升序列中的位置
j = lower_bound(arr, arr + len, num[i], cmp) - arr;
arr[j] = num[i];
len = max(j + 1, len);
}
printf("%d\n", len);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: