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. python报错

    报错1 UnboundLocalError: local variable 'x' referenced before assignment 定义了一个全局参数,但是在函数中直接改变参数值,就会报这个 ...

  2. the grave of my scripts

    不定期更新.......... 1,fetch_seq.py https://github.com/freemao/AHRD/blob/master/fetch_seq.py 提取出你想要得染色体的某 ...

  3. hdu 5902 Seam Carving

    水题,直接上代码了 #include<cstdio> #include<cstring> #include<iostream> #include<cmath& ...

  4. ZOJ 3872--解题报告

    题目相关: 3872相关链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520 Edward拥有一组数列. 其定义了Be ...

  5. 自动构建Makefile(1)--C/C++编译流程&Makefile规则简介

      前言: 大家在Windows上使用VS构建C/C++程序时,不需要自己编辑略显晦涩的Makefile文件,而对于初学者而言, 他们甚至没意识到它的存在.VS是自动生成Makefile文件, 并构建 ...

  6. 基础套接字的C#网络编程

    1.基于socket创建套接字网络连接服务端1.初始化 步骤 操作 方法 操作类 1. 创建ip ipaddress IPAddress类 2. 创建ip终结点   ipendpoint IpendP ...

  7. leetcode 102 Binary Tree Level Order Traversal ----- java

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  8. leetcode 38 Count and Say ---java

    这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 -->   111221 --> 312211 --> ..... 1个 ...

  9. LNMP环境搭建(discuz论坛)

    一.操作系统级环境及软件版本 操作系统:CentOS release 6.5 (Final)minimal 内核版本:2.6.32-431.el6.x86_64 MySQL版本:MySQL-5.6.2 ...

  10. jquery 按回城 等于提交按钮

    $(document).keydown(function(e){                    if(e.keyCode==13){                        $('.bu ...