• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            gzwzm06

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評(píng)論 :: 0 Trackbacks
            先求出最長非遞增子序列和最長非遞減子序列,由總長度減去其中較長的一個(gè)
             1#include <cstdio>
             2#include <algorithm> 
             3#include <vector> 
             4#include <list> 
             5#include <iterator> 
             6#include <limits>
             7using namespace std;
             8
             9const int SIZE = 30010;
            10
            11template<typename T>
            12int LIS(T Array[], int nCnt)
            13{
            14    if (nCnt == 0)
            15        return 0;
            16
            17    Array[nCnt++= numeric_limits<T>::max();
            18    
            19    T *= Array;
            20    vector<T> dp;
            21    dp.push_back(p[0]);
            22    int nRet = 1;
            23    for (int n = 1; n < nCnt; ++n)
            24    {
            25        T& e = p[n];
            26        typename vector<T>::iterator itor = upper_bound(dp.begin(), dp.end(), e, less<int>());
            27
            28        if ( itor == dp.end() )
            29            dp.push_back(e);
            30        else if (*itor > e)
            31            *itor = e;        
            32    }

            33
            34    return ((int)dp.size() - 1) ;
            35}

            36
            37template<typename T>
            38int LDS(T Array[], int nCnt)
            39{
            40    Array[nCnt++= numeric_limits<T>::min();
            41
            42    T *= Array;
            43    vector<T> dp;
            44    dp.push_back(p[0]);
            45    int nRet = 1;
            46    for (int n=1; n < nCnt; ++n)
            47    {
            48        T& e = p[n];
            49        typename vector<T>::iterator itor = upper_bound(dp.begin(), dp.end(), e, greater<int>());    
            50        
            51        if ( itor == dp.end() )
            52            dp.push_back(e);
            53        else if (*itor < e)
            54            *itor = e;        
            55    }

            56
            57    return (int)dp.size()-1;
            58}

            59
            60int array[SIZE];
            61
            62int main()
            63{
            64    int i, n, lis, lds;
            65
            66    scanf("%d"&n);
            67
            68    for ( i = 0; i < n; ++i )
            69    {
            70        scanf("%d"&array[i]);
            71    }

            72
            73    lis = LIS(array, n);
            74    lds = LDS(array, n);
            75
            76    int ans = (lis > lds ? lis : lds);
            77
            78    printf("%d\n", n - ans);
            79    return 0;
            80}
            posted on 2009-03-22 19:55 閱讀(887) 評(píng)論(0)  編輯 收藏 引用 所屬分類: DP
            av无码久久久久久不卡网站| 93精91精品国产综合久久香蕉| 久久午夜综合久久| 久久精品国产乱子伦| 久久www免费人成看片| 精品久久香蕉国产线看观看亚洲| 久久久久亚洲AV无码专区网站| 亚洲国产精品无码久久一线| 97久久精品人人澡人人爽| 久久99久久99精品免视看动漫| 久久中文娱乐网| 久久综合给合久久狠狠狠97色69 | 九九久久99综合一区二区| 久久精品中文字幕有码| 精品蜜臀久久久久99网站| 日本久久中文字幕| 99热都是精品久久久久久| 午夜天堂精品久久久久| 欧美午夜A∨大片久久| 91精品国产91久久久久久蜜臀 | 久久国产精品久久| 日韩精品无码久久久久久| 久久香综合精品久久伊人| 欧美午夜A∨大片久久| 国产成人精品久久亚洲高清不卡| 久久婷婷五月综合97色| 久久亚洲国产精品成人AV秋霞 | 三级片免费观看久久| 久久久久一区二区三区| 国产精品久久久久9999高清| 亚洲女久久久噜噜噜熟女| 国产精品99久久久精品无码| 人妻无码精品久久亚瑟影视| 国内精品伊人久久久久影院对白 | 香蕉久久久久久狠狠色| 久久人人爽人人爽人人片AV麻豆 | 伊人久久综合热线大杳蕉下载| 国产精品18久久久久久vr| 99国产欧美久久久精品蜜芽| 久久99精品国产99久久6男男| 好属妞这里只有精品久久|