LintCode "Longest Increasing Continuous subsequence II" !!
DFS + Memorized Search (DP)
class Solution {
int dfs(int i, int j, int row, int col,
vector<vector<int>>& A, vector<vector<int>>& dp)
{
if(dp[i][j] != ) return dp[i][j];
if (i > && A[i-][j] > A[i][j])
{
dp[i][j] = max(dp[i][j], dfs(i - , j, row, col, A, dp));
}
if (i < row - && A[i+][j] > A[i][j])
{
dp[i][j] = max(dp[i][j], dfs(i + , j, row, col, A, dp));
}
if (j > && A[i][j-] > A[i][j])
{
dp[i][j] = max(dp[i][j], dfs(i, j - , row, col, A, dp));
}
if (j < col - && A[i][j+] > A[i][j])
{
dp[i][j] = max(dp[i][j], dfs(i, j + , row, col, A, dp));
}
return ++dp[i][j];
}
public:
/**
* @param A an integer matrix
* @return an integer
*/
int longestIncreasingContinuousSubsequenceII(vector<vector<int>>& A)
{
if (A.empty() || A[].empty()) return ;
int ret = ;
int row = A.size();
int col = A[].size();
vector<vector<int>> dp(row, vector<int>(col));
for(int i = ; i < row; i ++)
for(int j = ; j < col; j ++)
{
ret = max(ret, dfs(i, j, row, col, A, dp));
}
return ret;
}
};
LintCode "Longest Increasing Continuous subsequence II" !!的更多相关文章
- [LintCode] Longest Increasing Continuous subsequence
http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...
- [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...
- LintCode 397: Longest Increasing Continuous Subsequence
LintCode 397: Longest Increasing Continuous Subsequence 题目描述 给定一个整数数组(下标从0到n - 1,n表示整个数组的规模),请找出该数组中 ...
- Lintcode397 Longest Increasing Continuous Subsequence solution 题解
[题目描述] Give an integer array,find the longest increasing continuous subsequence in this array. An in ...
- Longest Increasing Common Subsequence (LICS)
最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- Longest Continuous Increasing Subsequence II
Description Given an integer matrix. Find the longest increasing continuous subsequence in this matr ...
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- 【Lintcode】076.Longest Increasing Subsequence
题目: Given a sequence of integers, find the longest increasing subsequence (LIS). You code should ret ...
随机推荐
- Xen虚拟机磁盘镜像模板制作(一)—Windows Server 2008(2012)
这段时间一直在研究如何制作一个适合Xen虚拟化的Windows Server 2008(2012)磁盘镜像,中间虽然遇到了一些阻挠,不过最终还是顺利解决,成功制作出了Xen Windows Serve ...
- Core Java Volume I — 3.6. Strings
3.6. StringsConceptually, Java strings are sequences of Unicode characters(Java的字符串是一个Unicode序列). Fo ...
- sass中mixin常用的CSS3
圆角border-radius @mixin rounded($radius){ -webkit-border-radius: $radius; -moz-border-radius: $radius ...
- dalvik虚拟内存管理之三——调试信息
转载自http://www.miui.com/thread-75063-1-1.html 1. verbosegc一般Java虚拟机要求支持verbosegc选项,输出详细的垃圾收集调试信息.dalv ...
- 理解 %IOWAIT (%WIO)
%iowait 是 “sar -u” 等工具检查CPU使用率时显示的一个指标,在Linux上显示为 %iowait,在有的Unix版本上显示为 %wio,含义都是一样的,这个指标常常被误读,很多人把它 ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- SQL编写
//用户表,用户ID,用户名称create table t_user (user_id int,username varchar(20));//用户帐户表,用户ID,用户余额(单位分)create t ...
- 基础套接字的C#网络编程
1.基于socket创建套接字网络连接服务端1.初始化 步骤 操作 方法 操作类 1. 创建ip ipaddress IPAddress类 2. 创建ip终结点 ipendpoint IpendP ...
- html5表单新特性
type=range 值区域范围 默认值(0-100) type=data 选择日期 type=color value='初始值' 颜色选择器控件 type=search 搜索框效果 type=im ...
- linux 命令查看CPU和内存信息
几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...