LIS严格递增和非递减模板

2017-09-10 16:51:03

writer:pprp

严格递增的LIS模板

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <vector>
#include <iostream>
using namespace std;

int a[10] = {0,1,5,3,6,9};
vector<int> v;
int main()
{
    v.clear();
    v.push_back(a[1]);
    for(int i=2;i<5;i++)
    {
        if(a[i] > v.back())
        {
            v.push_back(a[i]);
        }
        else
        {
            *lower_bound(v.begin(),v.end(),a[i]) = a[i];
        }
    }
    cout << v.size() << endl;
}

非递减LIS

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <vector>
#include <iostream>
using namespace std;

int a[10] = {0,1,5,3,3,6,9};
vector<int> v;
int main()
{
    v.clear();
    v.push_back(a[1]);
    for(int i=2;i<6;i++)
    {
        if(a[i] >= v.back())
        {
            v.push_back(a[i]);
        }
        else
        {
            *lower_bound(v.begin(),v.end(),a[i]) = a[i];
        }
    }
    cout << v.size() << endl;
}

 

posted @ 2017-09-10 16:55  pprp  阅读(326)  评论(0编辑  收藏  举报