POJ3903 Stock Exchange LIS最长上升子序列

POJ3903 Stock Exchange

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <vector>
 4 #include <algorithm>
 5 using namespace std;
 6 const int maxn = 1e5+5;
 7 int a[maxn];
 8 int main() {
 9     int n;
10     while (~scanf("%d",&n)) {
11         for (int i = 1; i <= n; ++i) scanf("%d",&a[i]);
12         vector<int> ve;
13         ve.push_back(a[1]);
14         for (int i = 2; i <= n; ++i) {
15             if (ve[ve.size()-1] < a[i]) {
16                 // 如果新进来的数比最后一个数大,那么直接插入
17                 ve.push_back(a[i]);
18             }
19             else {
20                 ve[lower_bound(ve.begin(),ve.end(),a[i])-ve.begin()] = a[i];
21             }
22         }
23         printf("%d\n",ve.size());
24     }
25     return 0;
26 }

 

posted @ 2019-11-01 17:38  麻辣猪仔  阅读(100)  评论(0编辑  收藏  举报