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. Redis应用案例,查找某个值的范围(转)

    原文:https://groups.google.com/forum/#!topic/redis-db/lrYbkbxfQiQ 本文来自Redis在Google Group上的一个问题,有一位同学发贴 ...

  2. MySQL整理(二)

    一.MySQL操作表的约束 MySQL提供了一系列机制来检查数据库表中的数据是否满足规定条件,以此来保证数据库表中数据的准确性和一致性,这种机制就是约束. (1)设置非空约束(NOT NULL),唯一 ...

  3. django xadmin app models 注册

    在app下新建adminx.py文件 # -*- coding: utf-8 -*- # 作者:神秘藏宝室 # 日期:2018/12/28 22:07 import xadmin from .mode ...

  4. Magento 本地搬家至网络服务器步骤

    1.将本地的Magento的数据库备份下来. 2.将本地的Magento网站资料做成ZIP资料. 3.将Magento网站 ZIP资料上传到服务器的域名指向的资料夹内. 4.将ZIP解压出来,移动到域 ...

  5. javascript 对象 原型 prototype

  6. koa2+mongoose搭建框架模型

    由于学的是java,所以此框架多少有点java的影子,我觉得不必排斥语言,只要思想好,所有语言均可以通用.项目分以下几层 app.js项目启动入口,类似于main函数 controller-view层 ...

  7. mysql中explain的用法

    mysql中explain的用法 最近在做性能测试中经常遇到一些数据库的问题,通常使用慢查询日志可以找到执行效果比较差的sql,但是仅仅找到这些sql是不行的,我们需要协助开发人员分析问题所在,这就经 ...

  8. spark[源码]-SparkEnv执行环境创建

    sparkEnv概述 sparkEnv是spark的执行环境,其中包括众多与Executor执行相关的对象.在local模式下Driver会创建Executor,local-cluster部署模式或者 ...

  9. 进度条Demo

    package threadAndRunnable; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swi ...

  10. linux上使用wget下载文件

    首次安装的centos操作系统是没有安装wget的,所以首先需要先安装wget,然后才能使用wget下载文件. 1.第一步,保证centos能正常连网.使用命令  :yum -y install wg ...