POJ3903 Stock Exchange LIS最长上升子序列

Posted wstong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
",ve.size());
24     }
25     return 0;
26 }

 

以上是关于POJ3903 Stock Exchange LIS最长上升子序列的主要内容,如果未能解决你的问题,请参考以下文章

POJ3903 Stock Exchange LIS最长上升子序列

POJ 3903 Stock Exchange 最长上升子序列模板题

1178 H. Stock Exchange

CF1178H Stock Exchange

POJ1860-Currency Exchange-判正环

POJ 1860 Currency Exchange (SPFA松弛)