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[] = {,,,,,};
vector<int> v;
int main()
{
v.clear();
v.push_back(a[]);
for(int i=;i<;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[] = {,,,,,,};
vector<int> v;
int main()
{
v.clear();
v.push_back(a[]);
for(int i=;i<;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严格递增和非递减模板的更多相关文章

  1. HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)

    6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...

  2. hdu5256序列变换(非递减子序列)

    题意(中文直接粘吧)序列变换 Problem Description     我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元 ...

  3. C++非类型模板参数

    对于函数模板与类模板,模板参数并不局限于类型,普通值也可以作为模板参数.在基于类型参数的模板中,你定义了一些具体的细节来加以确定代码,直到代码被调用时这些细节才被真正的确定.但是在这里,我们面对的是这 ...

  4. C++ Template之非类型模板参数

    非类型模板参数是通过基本变量类型引入,例如int,在使用时必须显式自定值,不能通过推断. 非类型模板参数的限制:不能是浮点数(在vc6.0上测试可以为浮点型),对象以及指向内部链接对象的指针. #in ...

  5. [LeetCode] Non-decreasing Array 非递减数列

    Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...

  6. [Swift]LeetCode665. 非递减数列 | Non-decreasing Array

    Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...

  7. HDU 5532 Almost Sorted Array (最长非递减子序列)

    题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...

  8. Leetcode 665.非递减数列

    非递减数列 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i ...

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

                                                                                  D. Once Again... You a ...

随机推荐

  1. VS调用python方法

    1.  安装python3.7 2.  Vs2010中配置python: 3.添加头文件:#include <Python.h> 4.问题:error LNK2001: 无法解析的外部符号 ...

  2. str文档

    文档 class str(object): """ str(object='') -> str str(bytes_or_buffer[, encoding[, e ...

  3. openssl生成证书server.key server.crt

    Key是私用秘钥,通常是RSA算法 Csr是证书请求文件,用于申请证书.在制作csr文件时,必须使用自己的私钥来签署申,还可以设定一个密钥. crt是CA认证后的证书文,签署人用自己的key给你签署凭 ...

  4. python中的抽象方法

    python中的抽象方法 父类要限制1.子类必须有父类的方法2.子类实现的方法必须跟父类的方法的名字一样 import abc class A(metaclass=abc.ABCMeta): @abc ...

  5. python服务器环境搭建——安装相关软件

    在上一篇我们在本地的虚拟服务器上安装好CentOS7后,我们的python web服务.自定义的python service或python脚本需要在服务器上运行,还需要在服务器安装各种相关的软件才行, ...

  6. CanvasRenderingContext2D.imageSmoothingEnabled

    https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled 这是一个 ...

  7. MySQL5.7密码安全策略(转)

    环境介绍:CentOS 6.7 MySQL版本:5.7.11 1.查看现有的密码策略 mysql> SHOW VARIABLES LIKE 'validate_password%';参数解释:1 ...

  8. Linux常见错误之Could not get lock /var/lib/dpkg/lock - open

    在Ubuntu系统上安装vim是遇到的问题: root@ubuntu:/# vim The program 'vim' can be found in the following packages: ...

  9. CSS 换行知多少: word-wrap && word-break && white-space && word-spacing

    word-wrap : 首先提一下,word-wrap 这个 CSS 属性在CSS3中已经被更名为 overflow-wrap,这样语义化也是为了避免与 word-break 混淆: Referenc ...

  10. python全栈开发从入门到放弃之socket网络编程基础

    网络编程基础 一 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构 互联网中处处是C/S架构 如黄色网站是服务端,你的浏览器是客户端(B/S架构也是C/S架构的一种) 腾讯作为服务 ...