[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 ...
随机推荐
- session和request的区别
request 请求对象 请求中保存请求过程中需要的参数 比如另一个页面需要使用的对象编号,list,map等,请求结束,就失效了 session 会话对象 除非关闭会话(到时间通常为30分钟,或者关 ...
- python 闭包(closure)
闭包的定义: 闭包就是一个函数,这个函数可以记住封闭作用域里的值,而不管封闭作用域是否还在内存中. 来一个例子: def happy_add(a): print 'id(a): %x' % id(a) ...
- struts中的helloword(1)
注:文章中的所有图片均在附件中明白表明 首先要安装jdk1.6以及tomcat6和myeclipse 对于这些配置的安装 这里不再细细说明 其次是下载struts2 第一步:去struts21 ...
- 如何用JAVA生成注册序列号
原文:http://blog.csdn.net/eagleking012/article/details/7099900 平常我们都接触过软件注册,输入序列号.激活码.注册码.授权码:对于这些字符码到 ...
- [Bootstrap] 5. Button and well
Element Identification There are a number of classes in Bootstrap that help add prominence to a page ...
- C++和python使用struct传输二进制数据结构来实现
网络编程问题往往涉及二进制数据的传输.在C++经常使用的传输是文本字符串和分组结构. 假设该数据可以预先送入连续的内存区域,然后让send函数来获得的第一个地址,这一块连续的内存区就能完成传输数据.文 ...
- 编写函数,以读模式打开一个文件,将其内容读入到一个string的vector中,将每一行作为一个对立的元素存于vector中
#include<iostream> #include<string> #include<vector> #include<fstream> using ...
- [009]C---关于输出文本的打印问题
现在有这样一个问题: 针对一个long类型的变量,我们想把它打印成为32位显示. #include "stdio.h" int main() { long i =0xa; prin ...
- Java 之 调用.Net的 WebService 整理
最近做一个 java 调用 .net 服务的项目,其中 .net做了一个WebService,需要java来调用. 最开始.net的Service代码如下: using System; using S ...
- 关于JFace中的向导式对话框(WizardDialog类)
向导式对话框是一种非常友好的界面,它能够引导用户一步步的输入信息.Eclipse的"新建项目",就是这样的向导式对话框. 在Eclipse中向导式对话框的开发是很简单的,它由Wiz ...