zoukankan      html  css  js  c++  java
  • 51Nod 1134 最长递增子序列(动态规划O(nlogn))

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <stdio.h>
     4 #define MAXN 50010
     5 using namespace std;
     6 
     7 const int MIN = -1e9;
     8 
     9 int main(void){
    10     int n, a[MAXN], vis[MAXN], len = 1; 
    11     scanf("%d", &n);
    12     for (int i = 0; i<n; i++){
    13         scanf("%d", &a[i]);
    14     }
    15     for (int i = 0; i <= n; i++){
    16         vis[i] = MIN;
    17     }
    18 
    19     //vis[i]表示满足递增数量i的最小值 
    20     vis[1] = a[0];
    21     for (int i = 1; i<n; i++){
    22         //upper_bound(vis + 1, vis + len + 1, a[i]) 返回被查序列中第一个大于查找值的指针
    23         int pos = upper_bound(vis + 1, vis + len + 1, a[i]) - vis;
    24         vis[pos] = a[i];
    25         if (len<pos){ //维护最大长度
    26             len = pos;
    27         }
    28     }
    29     printf("%d
    ", len);
    30     return 0;
    31 }
  • 相关阅读:
    Heroku
    Git基本命令(转)
    github之从零开发
    物理层、、。。。
    BeautifulSoup, 的使用
    路径设置
    http协议
    Python 的os模块与sys模块
    python 操作MySQL数据库
    多进程记要
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8726917.html
Copyright © 2011-2022 走看看