[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 ...
随机推荐
- 手把手教你入门mac idea
一.前沿 去年入职后, 公司有很多人使用的是idea , 而不是eclipse. 之前就想转向idea, 但一直没转过来~~原因是团队的人提倡用开源eclipse.现在下定决心转向idea. 虽然, ...
- centos6.2安装jdk7
首先在Vmware下安装好Centos6.2,下载好jdk7文件,tar包安装 1 wget http://download.oracle.com/otn-pub/java/jdk/last-vers ...
- ORM之二:核心接口与扩展操作
一.数据库提供者接口 /// <summary> /// 数据库提供者 /// </summary> public interface IDbProvider : IDispo ...
- Ledongli
Ledongli.rar
- RotatingDoughnut
RotatingDoughnut.zip
- 学习笔记之DB2 9 Fundamentals 730
Sequence中cache的影响,每新建一个连接,next value值增加increment * cache.如果加上order,则会按顺序生成值. increment cache ; Conne ...
- TextView设置动态改变颜色
通过TextView的setTextColor方法进行文本颜色的设置, 这里可以有3种方式进行设置: 第1种:tv.setTextColor(android.graphics.Color.RED);/ ...
- C语言结构体的强制类型转换
陈浩师兄03年的一篇博客<用C写有面向对象特点的程序>描述了用C语言来实现类似C++类继承的方法,这样方法的核心要点就是结构体的强制类型转换,让我来简单分析分析C语言中的结构体强制类型转换 ...
- Linux下安装MATLAB的一些注意事项
1,下载matlab的linux版本. matlab2012a的种子文件, Matlab_Unix_2012a.torrent 我是在window机子上下载了MATLAB的Linux版本. 2,把MA ...
- highcharts 去掉右下角链接
去掉右下角的highcharts.com链接需要加入以下代码: credits: { enabled:false }, 如果不设置,那么默认为显示.