LIS严格递增和非递减模板
Posted pprp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
以上是关于LIS严格递增和非递减模板的主要内容,如果未能解决你的问题,请参考以下文章
POJ 1836 Alignment 最长递增子序列(LIS)的变形