[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 ...
随机推荐
- The maximum number of cell styles was exceeded. You can define up to 4000 styles
POI操作Excel中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时, 就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面 ...
- Mac OS X 10.10优胜美地怎样完美接管iphone上的电话和短信
自从今年苹果第一次的公布会上毛猫就特别注意这个功能.感觉特别Cool,特别方便.但直到今天毛猫才第一次成功測试出这个功能呀.尽管handoff功能还未測出来,可是认为在mac上发短信和打电话也已经足够 ...
- FindWindow使用方法
函数功能:该函数获得一个顶层窗体的句柄,该窗体的类名和窗体名与给定的字符串相匹配.这个函数不查找子窗体.在查找时不区分大写和小写. 函数型:HWND FindWindow(LPCTSTR IpClas ...
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp
C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- glog摘记
projcet url:https://code.google.com/p/google-glog/ usage: application-level logging setting flags GL ...
- android自动打包方法(ant+proguard+签名)
前段时间做了一个android的网游项目,现在优化减少体积和防止别人反编译,需要把编译后.class进行混淆,开始在网上看了一些关于 ProGuard的介绍,基本上都是使用ADT自带的打包方式,那个打 ...
- android学习日记13--数据存储之SharedPreference
android 数据存储 作为一个完整的应用程序,数据存储必不可少.android 提供了五种不同的数据存储方式:SharedPreferences.SQLite.ContentProvider.文件 ...
- uboot中gd的定义和使用
近期在做uboot中nand启动相关的工作,遇到一个问题一直纠结着.如今最终明确了这个问题,想想还有好多兄弟在某个黑暗的角落里或者某台电脑前纠结着呢,所以赶紧写下来以供查阅. uboot versio ...
- MySQL 资源大全中文版
https://github.com/jobbole/awesome-mysql-cn