[leetcode]最长递增序列
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int n=nums.size();
if(n==) return ;
vector<int> maxv(n+);
maxv[]=INT_MIN;
maxv[]=nums[];
vector<int> lis(n);
lis[]=;
int nMaxLen=;
for(int i=;i<n;i++)
{
int j;
for(j=nMaxLen;j>=;j--)
{
if(nums[i]>maxv[j])
{
lis[i]=j+;
break;
}
}
if(j==nMaxLen)
{
maxv[j+]=nums[i];
nMaxLen=j+;
}
else if(nums[i]<maxv[j+])
{
maxv[j+]=nums[i];
}
}
for(auto &x: maxv)
cout<<x<<" ";
cout<<endl;
for(auto &x:lis)
cout<<x<<" ";
cout<<endl;
return nMaxLen;
}
};
[leetcode]最长递增序列的更多相关文章
- [LeetCode] Number of Longest Increasing Subsequence 最长递增序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- [LeetCode] 673. Number of Longest Increasing Subsequence 最长递增序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- Leetcode 674.最长递增序列
最长递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3 ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- uva103(最长递增序列,dag上的最长路)
题目的意思是给定k个盒子,每个盒子的维度有n dimension 问最多有多少个盒子能够依次嵌套 但是这个嵌套的规则有点特殊,两个盒子,D = (d1,d2,...dn) ,E = (e1,e2... ...
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- LeetCode OJ:Longest Increasing Subsequence(最长递增序列)
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- ACM: Racing Gems - 最长递增序列
Racing Gems You are playing a racing game. Your character starts at the x axis (y = 0) and procee ...
- leetcode 最长连续序列 longest consecutive sequence
转载请注明来自souldak,微博:@evagle 题目(来自leetcode): 给你一个n个数的乱序序列,O(N)找出其中最长的连续序列的长度. 例如给你[100, 4, 200, 1, 3, 2 ...
随机推荐
- jquery timepicker
<div class="form-group row"> <div class="col-lg-2 control-label l-pd25" ...
- 学习和理解C#中的事件
注:本文系学习笔记. 上一篇文章记录了我对C#中委托的理解.委托实际上是一种类型.可以将一个或多个方法绑定到委托上面,调用委托时,一次执行委托上面绑定的方法.本文要讲述的事件实际上和委托有很深的“感情 ...
- 一些好用的nginx第三方模块
一些好用的nginx第三方模块 转自;http://macken.iteye.com/blog/1963301 1.Development Kit https://github.com/simpl/ ...
- 用intent打开各种类型文件
public class MyIntent { //android获取一个用于打开HTML文件的intent public static Intent getHtmlFileIntent( Strin ...
- 详解UML中的聚合,关联,泛化等关系
1. Overview UML设计类中,类的关系分为Generalization(泛化),Dependency(依赖关系).Association(关联关系).Aggregation(聚合关系).Co ...
- C++ Primer 学习笔记_76_模板与泛型编程 --模板定义[续]
模板与泛型编程 --模板定义[续] 四.模板类型形參 类型形參由keywordclass或 typename后接说明符构成.在模板形參表中,这两个keyword具有同样的含义,都指出后面所接的名字表示 ...
- 通过IP控制登录系统
项目中有这么一个需求,就是系统仅仅能在指定ip下登录,能够理解为内部系统,仅仅能够在公司訪问 我的代码是这样写的:入不入流不知道,但能解决这个问题. 获得訪问IP代码: String ip = req ...
- W5500问题集锦(二)
attachment_id=5620" rel="attachment wp-att-5620" style="margin:0px; padding:0px; ...
- Xposed知识
最近闹得沸沸扬扬的MIUI抄袭Xposed不署名事件,为此在这里普及一下相关的Xposed的知识. 相关资源 source code: https://github.com/rovo89 online ...
- php中用户自定义排序
php中数组用户自定义排序函数有usort和uasort,前者键值重新排列,后者保持原数组的键值. 举例usrot: usort($filterArr, 'sortArr'); function so ...