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[] = {,,,,,};
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严格递增和非递减模板的更多相关文章
- HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...
- hdu5256序列变换(非递减子序列)
题意(中文直接粘吧)序列变换 Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元 ...
- C++非类型模板参数
对于函数模板与类模板,模板参数并不局限于类型,普通值也可以作为模板参数.在基于类型参数的模板中,你定义了一些具体的细节来加以确定代码,直到代码被调用时这些细节才被真正的确定.但是在这里,我们面对的是这 ...
- C++ Template之非类型模板参数
非类型模板参数是通过基本变量类型引入,例如int,在使用时必须显式自定值,不能通过推断. 非类型模板参数的限制:不能是浮点数(在vc6.0上测试可以为浮点型),对象以及指向内部链接对象的指针. #in ...
- [LeetCode] Non-decreasing Array 非递减数列
Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...
- [Swift]LeetCode665. 非递减数列 | Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- Leetcode 665.非递减数列
非递减数列 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i ...
- Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
D. Once Again... You a ...
随机推荐
- 重装系统后Myeclipse遇到的项目配置问题--一个菜鸟的经历!
电脑不知道为什么流量突然变大了. 一查svchost.exe后台下载老多系统.某某安全卫士根本么用,运维说用某企鹅管家. 结果一个鸟样.. 之前是系统是32位的win7 4G内存用不完.又打算升级内 ...
- 【非root用户】安装【python,pip,package】
安装python: 下载源码 解压 进入 ./configure --prefix=/path/python3.6 注意一定要设置prefix,否则默认安装到/usr/local make make ...
- Buy the souvenirs---hdu2126(01背包输出方案数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2126 有n个物品每个物品的价格是v[i],现在有m元钱问最多买多少种物品,并求出有多少种选择方法: 如 ...
- CNI插件编写框架分析
概述 在<CNI, From A Developer's Perspective>一文中,我们已经对CNI有了较为深入的了解.我们知道,容器网络功能的实现最终是通过CNI插件来完成的.每个 ...
- Linux命令(基础2)
1.命令概要介绍: 查看目录内容:ls 切换目录命令:cd 创建与删除目录:touch(创建文件).rm(移除文件与目录).mkdir(创建目录) 拷贝与移动命令:cp(拷贝).mv(移动) 查看文件 ...
- vs2010 重新配置帮助文档
1.VS2010帮助文件不支持重新配置,这个时候打开C:\Program Files\Microsoft Help Viewer\1.0目录,找到“HelpLibManager.exe.config” ...
- JavaScript:学习笔记(9)——Promise对象
JavaScript:学习笔记(9)——Promise对象 引入Promise Primose是异步编程的一种解决方案,比传统的解决方案回调函数和事件更加合理和强大.如下面为基于回调函数的Ajax操作 ...
- 48. Rotate Image(旋转矩阵)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise) ...
- codeforces 70 D. Professor's task 动态凸包
地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 secon ...
- scala drools and map
需求,安全检查,例如Linux系统,用户安全检查,配置项检查等,这些检查的规则在Drools里面去实现,数据传送过来即可, 问题:如何定义数据结构,不同的检查项会有不同的数据结构,如何规范呢? 思路: ...