https://leetcode.com/problems/longest-increasing-subsequence/

Given an unsorted array of integers, find the length of longest increasing subsequence.

For example,
Given [10, 9, 2, 5, 3, 7, 101, 18],
The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for you to return the length.

Your algorithm should run in O(n2) complexity.

Follow up: Could you improve it to O(n log n) time complexity?

class Solution {
public:
int dfs(vector<int>& nums, vector<int> &dp, int v) {
if(dp[v]) return dp[v];
if(v == ) return ; int res = -;
for(int nv=v-;nv>=;--nv) {
if(nums[nv] >= nums[v]) continue;
res = max(res, dfs(nums, dp, nv));
}
dp[v] = res + ;
return dp[v];
}
int lengthOfLIS(vector<int>& nums) {
if(nums.size() == || nums.size() == ) return nums.size(); vector<int> dp(nums.size(), ); int res = -;
for(int i=nums.size()-;i>=;--i) {
dp[i] = dfs(nums, dp, i);
res = max(res, dp[i] + );
} return res;
}
};

leetcode@ [300] Longest Increasing Subsequence (记忆化搜索)的更多相关文章

  1. [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  2. LeetCode 300. Longest Increasing Subsequence最长上升子序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest increasing subsequence. Example: ...

  3. Leetcode 300 Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  4. [leetcode]300. Longest Increasing Subsequence最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  5. [leetcode] 300. Longest Increasing Subsequence (Medium)

    题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...

  6. LeetCode——300. Longest Increasing Subsequence

    一.题目链接:https://leetcode.com/problems/longest-increasing-subsequence/ 二.题目大意: 给定一个没有排序的数组,要求从该数组中找到一个 ...

  7. 【LeetCode】300. Longest Increasing Subsequence 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. 【leetcode】300.Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  9. 【刷题-LeetCode】300. Longest Increasing Subsequence

    Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...

随机推荐

  1. [Ruby on Rails系列]2、开发环境准备:Ruby on Rails开发环境配置

    前情回顾 上次讲到Vmware虚拟机的安装配置以及Scientific Linux 6.X系统的安装.这回我们的主要任务是在Linux操作系统上完成Ruby on Rails开发环境的配置. 在配置环 ...

  2. live555源码研究(一)------live555MediaServer的启动过程和基本类图

    live555MediaServer.cpp就是live555服务器启动的过程. 一.启动过程 1,构造运行环境,运行环境包括了TaskScheduler 2,构造鉴权数据,也就是登陆的用户名和密码等 ...

  3. nchar 和 nvarchar

    字符数据类型(nchar 长度固定,nvarchar 长度可变)和 Unicode 数据使用 UNICODE UCS-2 字符集. nchar [ ( n ) ] n 个字符的固定长度的 Unicod ...

  4. SRM 587 DIV1

    要掉到DVI2了..好不容这次的250那么简单,500的题知道怎么做,可惜没调出来500. 250的题很简单,从第1步到第N步,每次要么不做,要么走i步,且X不能走,问说最远走多远. #include ...

  5. php/ java/asp.net

    php大型网站用得多 企业级开发 java/asp.net用得多 这个很好理解 php 执行效率好 可塑性强 接近底层 java asp.net 封装了更多的东西,开发企业级业务 效率更高, 但是高性 ...

  6. PHP开发搜索引擎技术全解析

    谈到网页搜索引擎时,很多人都会想到雅虎.的确,雅虎开创了一个互联网络的搜索时代.然而,雅虎目前用于搜索网页的技术却并非该公司原先自己开发的.2000年8月,雅虎采用了Google这家由斯坦福大学学生创 ...

  7. 使用PHP抓取网站ico图标

    网站许久没用更新,以后会经常更新,本次分享一个使用PHP抓取网站ico的程序,提供一个网站列表后对网站的ico进行下载抓取,具体代码如下: <?php /** * 更新热站ico * gao 2 ...

  8. Annotation【转】

    1.Annotation的工作原理: JDK5.0中提供了注解的功能,允许开发者定义和使用自己的注解类型.该功能由一个定义注解类型的语法和描述一个注解声明的语法,读取注解的API,一个使用注解修饰的c ...

  9. Redpine的Lite-Fi解决方案获Wi-Fi CERTIFIED认证

    应用微电路公司(AMCC)和Redpine Signals日前共同宣布,已合作开发出新一代基于Power Architecture的嵌入式Wi-Fi连接性解决方案,目前双方已经在AMCC的PowerP ...

  10. 【HDOJ】4652 Dice

    1. 题目描述对于m面的骰子.有两种查询,查询0表示求最后n次摇骰子点数相同的期望:查询1表示最后n次摇骰子点数均不相同的期望. 2. 基本思路由期望DP推导,求得最终表达式.(1) 查询0    不 ...