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;
}
时间: 2024-07-31 21:53:04

LIS严格递增和非递减模板的相关文章

HDU 1025 Constructing Roads In JGShining&#39;s Kingdom[动态规划/nlogn求最长非递减子序列]

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27358    Accepted Submission(s): 7782 Problem Description JGShining's kingdom consists of 2n(n is no mor

顺序表的非递减数列合并

#include<stdio.h> /*包含输入输出头文件*/ #define ListSize 100 typedef int DataType; typedef struct { DataType list[ListSize]; int length; }SeqList; void InitList(SeqList *L) /*将线性表初始化为空的线性表只需要把线性表的长度length置为0*/ { L->length=0; /*把线性表的长度置为0*/ } int ListEmpt

Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                              D. Once Again... You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of

非递减顺序表的合并

//顺序表的合并 //输入元素函数 put //输出元素函数 output //合并 Merge #include<stdio.h> #include<stdlib.h> #include<algorithm> using namespace std; #define LIST_INIT_SIZE 80 #define LISTINCREMENT 10 typedef struct { int *elem; int length; //有效长度 int size; //

Gym 100952H Special Palindrome 非递减的回文串、dfs打表、查数列网站OEIS

H - H Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100952H Description standard input/output Statements A sequence of positive and non-zero integers called palindromic if it can be read the s

链式表的非递减数列合并

/*包含头文件*/ #include<stdio.h> #include<malloc.h> #include<stdlib.h> /*宏定义和单链表类型定义*/ #define ListSize 100 typedef int DataType; typedef struct Node { DataType data; struct Node *next; }ListNode,*LinkList; void MergeList(LinkList A,LinkList

17、把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1. NOTE:给出的所有元素都大于0,若数组大小为0,请返回0. eg: 输入 3 4 5 1 2 输出 1 思路:用二分法查找最小元素 三种情况: (1)rotateArray[mid] >rotateArray[high]: like:[x,x,x,6,x,x,2],此时最小数字一

C++非类型模板参数

对于函数模板与类模板,模板参数并不局限于类型,普通值也可以作为模板参数.在基于类型参数的模板中,你定义了一些具体的细节来加以确定代码,直到代码被调用时这些细节才被真正的确定.但是在这里,我们面对的是这些细节是值,而不是类型,当要使用基于值的模板时,必须显式地指定这些值,才能够对模板进行实例化. 本文地址:http://www.cnblogs.com/archimedes/p/cpp-template-type.html,转载请注明源地址. 在上篇文章(C++类模板)中我们介绍了一个stack类模

非类型模板参数

对于函数模板与类模板,模板参数并不局限于类型,普通值也可以作为模板参数.在基于类型参数的模板中,你定义了一些具体的细节来加以确定代码,直到代码被调用时这些细节才被真正的确定.但是在这里,我们面对的是这些细节是值,而不是类型,当要使用基于值的模板时,必须显式地指定这些值,才能够对模板进行实例化. 非类型的类模板参数 创建类的头文件 #include<stdexcept> #include<iostream> using namespace std; template<typen