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. Android开发之Java必备基础

    Android开发之Java必备基础 Java类型系统 Java语言基础数据类型有两种:对象和基本类型(Primitives).Java通过强制使用静态类型来确保类型安全,要求每个变量在使用之前必须先 ...

  2. 解决:“MediaPlayer error (1, -2147483648)”问题

    如果你使用VideoView播放过MP4视频,你可能碰到过类似下面的问题: MediaPlayer   error (1, -2147483648) 如果你查阅文档,会发现1其实代表MEDIA_ERR ...

  3. Web上下文配置【MvcConfig】

    基于Servlet3.0规范和SpringMVC4注解式配置方式,实现零xml配置,弄了个小demo,供交流讨论. 项目说明如下: 1.db.sql是项目中用到的表,数据库使用的是oracle11g ...

  4. C陷阱与缺陷 2

    1,数组 对数组只能进行两种操作,1确定数组的大小,2获得数组第一个元素的指针,其他的操作均是通过指针来实现的. 1 2 3 4 5 6 7 8 9 #include <stdio.h> ...

  5. Xcode7.0.1(ios9)的部分适配问题

    今天更新了Xcode 7 正式版,App编译出现很多警告,在App运行的时候出现如下的提示......... the resource could not be loaded because the ...

  6. 论文笔记之:Spatially Supervised Recurrent Convolutional Neural Networks for Visual Object Tracking

    Spatially Supervised Recurrent Convolutional Neural Networks for Visual Object Tracking  arXiv Paper ...

  7. C语言 文件读取

    FILE *fp = fopen("data.txt","rt");fscanf(fp,"%d", &n ); /* 把数据放到数组 ...

  8. MMU讲解

    MMU是Memory Management Unit的缩写,中文名是内存管理单元,它是中央处理器(CPU)中用来管理虚拟存储器.物理存储器的控制线路,同时也负责虚拟地址映射为物理地址,以及提供硬件机制 ...

  9. SHOW OPEN TABLES – what is in your table cache

    One command, which few people realize exists is SHOW OPEN TABLES – it allows you to examine what tab ...

  10. Linux 用户态和内核态

    1.特权级特权级用来管理和控制程序执行.如Intel x86架构的CPU,有0~3四个特权级,0级最高,3级最低.硬件在执行每条指令时都会检查指令具有的特权级.硬件提供了特权级使用机制,对操作系统来说 ...