POJ 3903 Stock Exchange 最长上升子序列入门题

匿名 (未验证) 提交于 2019-12-02 23:32:01

题目链接:http://poj.org/problem?id=3903
最长上升子序列入门题。
算法时间复杂度 O(n*logn)
代码:

#include <iostream> #include <algorithm> using namespace std; const int maxn = 100010; int n, a[maxn], f[maxn], maxlen = 0;  int main() {     while (cin >> n) {         maxlen = 0;         for (int i = 1; i <= n; i ++) cin >> a[i];         for (int i = 1; i <= n; i ++) {             int idx = lower_bound(f, f+maxlen, a[i]) - f;             if (idx >= maxlen) {                 f[maxlen++] = a[i];             } else {                 f[idx] = a[i];             }         }         cout << maxlen << endl;     }     return 0; } 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!