[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 ...
随机推荐
- orderby group by
说到SQL语句,大家最開始想到的就是他的查询语句: select* from tableName: 这是最简单的一种查询方式,不带有不论什么的条件. 当然在我们的实际应用中,这条语句也是非经常常使用到 ...
- linux修改文件权限和用户组管理小结
如何在linux下修改组权限 chmod g+r path/file 加读权限 当前目录 chmod -R g+r path/file 加读权限 当前目录以及子目录 g-r 减读权限g+w 加写权限g ...
- 【转】如何从零开始学会 Ruby on Rails?
文章转自:http://huacnlee.com/blog/how-to-start-learning-ruby-on-rails/ 这个话题曾经给身边的很多朋友说过同样的话题,这里整理以下. 如果你 ...
- Java Swing界面编程(1)
写多了jsp,对于页面式的系统已经写烦了,本人也開始着手于java swing的学习,作为菜鸟,仅想用博客记录下我的swing学习的历程.话不多说,首先開始我的第一个窗体化程序. 下面给出源码: pa ...
- Oracl数据库管理方面的资料(查询sga,查看oracle数据库名称sid,查看oracle数据库名称,查看表空间,修改表空间名称)
显示Oracle sga相关信息: SQL> show sga Total System Global Area 105978600 bytes Fixed Size 453352 bytes ...
- C_数据结构_链表的链式实现
传统的链表不能实现数据和链表的分离,一旦数据改变则链表就不能用了,就要重新开发. 如上说示:外层是Teacher,里面小的是node. #ifndef _MYLINKLIST_H_ #define _ ...
- Ruby简介,附带示例程序
Ruby语言是日本人松本行弘于1993年器开始着手研发,经历2年时间,发布了Ruby语言的第一个版本:0.95版. Ruby是一种非常简介的解释性语言,一种纯粹的面向对象编程语言,甚至比Jav ...
- JAVA白盒安全测试需要关注的API
JAVA白盒安全测试需要关注的APIhttp://blog.csdn.net/testing_is_believing/article/details/19502167
- gitHub添加公钥
gitHub添加公钥 gitHub是通过SSH公钥连接到现有仓库的 设置SSH Key ssh-keygen -t rsa -C "your_email@example.com"G ...
- 关于国际化中的$NON-NLS-1$
百度百科解释: 这实际与eclipse中支持i18n的一种方式,eclipse的标准结构,将所有string常量定义到·properties中,例如下面程序段中的TestRef.hello实际上是·p ...