zoukankan      html  css  js  c++  java
  • 波浪子序列 (Wavio Sequence,UVa 10534)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 #define MAXN 10002
    15 
    16 int main()
    17 {
    18     int a[MAXN];
    19     int n;
    20     int g[MAXN];
    21     int up[MAXN],down[MAXN];
    22     while(scanf("%d",&n)!=EOF)
    23     {
    24         for(int i=0;i<n;i++)
    25         scanf("%d",&a[i]);
    26         int ans=-1;
    27         for(int i=0;i<=n;i++)g[i]=INF;
    28         for(int i=0;i<n;i++)
    29         {
    30         int k=lower_bound(g+1,g+n+1,a[i])-g;
    31         up[i]=k;
    32         g[k]=a[i];
    33         }
    34 
    35         for(int i=0;i<=n;i++)g[i]=INF;
    36         for(int i=n-1;i>=0;i--)
    37         {
    38         int k=lower_bound(g+1,g+n+1,a[i])-g;
    39         down[i]=k;
    40         g[k]=a[i];
    41         }
    42 
    43         for(int i=0;i<n;i++)
    44         {
    45             ans=max(ans,min(up[i],down[i])*2-1);
    46         }
    47         printf("%d
    ",ans);
    48     }
    49     return 0;
    50 }

    刘汝佳的 O(nlogn) 的 LIS 算法

    lower_bound(first,last,value)在first和last中的前闭后开区间进行二分查找,返回大于或等于value的第一个元素位置。如果所有元素都小于val,则返回last的位置。

  • 相关阅读:
    retain,copy,mutableCopy的区别
    xcode 添加mainWindow.xib
    ios 协议代理
    mysql基础
    mysql常用语句(转)
    mysql的13个使用技巧(转)
    mysql性能优化教程(转)
    mysql学习资源(转)
    find命令详解(转)
    vim基础操作(转)----附vim壁纸
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3200178.html
Copyright © 2011-2022 走看看