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" !!的更多相关文章

  1. [LintCode] Longest Increasing Continuous subsequence

    http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...

  2. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列

    Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...

  3. LintCode 397: Longest Increasing Continuous Subsequence

    LintCode 397: Longest Increasing Continuous Subsequence 题目描述 给定一个整数数组(下标从0到n - 1,n表示整个数组的规模),请找出该数组中 ...

  4. Lintcode397 Longest Increasing Continuous Subsequence solution 题解

    [题目描述] Give an integer array,find the longest increasing continuous subsequence in this array. An in ...

  5. Longest Increasing Common Subsequence (LICS)

    最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...

  6. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  7. Longest Continuous Increasing Subsequence II

    Description Given an integer matrix. Find the longest increasing continuous subsequence in this matr ...

  8. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  9. 【Lintcode】076.Longest Increasing Subsequence

    题目: Given a sequence of integers, find the longest increasing subsequence (LIS). You code should ret ...

随机推荐

  1. C语言Makefile文件使用

    C语言中代码Makefile文件的写法 单文件,例: #定义变量 CFLAGS=gcc #具体命令都需要一个入口,all: 这个就相当于入口,默认情况,执行第一次入口, #后面执行其他入口进行依赖,如 ...

  2. The implementation of Lua 5.0 阅读笔记(二)

    6 线程和协程 读完这篇文章我才意识到python的协程到底缺了什么,这个就是coroutine和semi-coroutine的区别了.区别就是,semi-coroutine只能返回(yield)到调 ...

  3. ARM异常中断处理

    ARM异常中断处理 在ARM体系中,通常有以下3种方式控制程序的执行流程: 在正常程序执行过程中,每执行一条ARM指令,程序计数器寄存器(PC)的值加4个字节:每执行一条Thumb指令,程序计数器寄存 ...

  4. 五 浅谈CPU 并行编程和 GPU 并行编程的区别

    前言 CPU 的并行编程技术,也是高性能计算中的热点,也是今后要努力学习的方向.那么它和 GPU 并行编程有何区别呢? 本文将做出详细的对比,分析各自的特点,为将来深入学习 CPU 并行编程技术打下铺 ...

  5. Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.

    svn更新代码后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened because the project file cannot be parsed ...

  6. [转]CentOS6.3安装JDK和环境配置

    转自:http://www.linuxidc.com/Linux/2012-09/70780.htm 1.CentOS默认情况下,会安装OpenOffice之类的软件,这些软件需要Java的支持,默认 ...

  7. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

  8. 渴切-开源中文css框架

    渴切:是国内优秀的开源css框架. 渴切是一个开源中文 (X)HTML/CSS 框架 ,它的目的是减少你的css开发时间.它提供一个可靠的css基础去创建你的项目,能够用于网站的快速设计,通过重设和重 ...

  9. dir:一行代码,提取出所有视频文件名称及路径

    某次,部门接到一个任务,要求对公司现有的视频文件资料做一个统计整理分类的工作. 领导召集开会,问:两周时间够用吗? 统计整理分类工作的第一步骤是把视频文件名称来源类别信息录入到 excel 表格中,才 ...

  10. 执行bat文件

    set CLASSPATH=E:\kuaipan\work\J2SE_workspace\JavaSEbasic\bin;E:\kuaipan\study\jar\jxl\*; set HEAP=-X ...