这题状态方程很容易得到:DP[i][j] = max(DP[i-1][j],DP[i+1][j],DP[i][j-1],DP[i][j+1]) + 1

难点在于边界条件和剪枝,因为这方程的条件是点在map里,且只有递增关系才会变化,如果用循环的话要判断递增,所以用递归比较方便

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long int n,m,V;
int dp[][],map[][]; int f(int i,int j)
{
if(dp[i][j]!=)
return dp[i][j];
int w,s,a,d;
if(i->=)
{
if(map[i-][j]<map[i][j]) s=f(i-,j)+;
else s=;
}
else s=;
if(i+<=n)
{
if(map[i+][j]<map[i][j]) w=f(i+,j)+;
else w=;
}
else w=;
if(j->=)
{
if(map[i][j-]<map[i][j]) a=f(i,j-)+;
else a=;
}
else a=;
if(j+<=m)
{
if(map[i][j+]<map[i][j]) d=f(i,j+)+;
else d=;
}
else d=; int max1 = max(w,s);
int max2 = max(a,d);
return max(max1,max2); } int main()
{
int i,j,t;
while(~sf("%d%d",&n,&m))
{
mem(dp,);
dp[][] =;
for(i=;i<=n;i++)
{
for(j = ;j<=m;j++)
sf("%d",&map[i][j]);
}
int max = ;
for(i=;i<=n;i++)
{
for(j = ;j<=m;j++)
{
dp[i][j]=f(i,j);
if(max<dp[i][j]) max = dp[i][j];
}
}
pf("%d\n",max); }
}

poj 1088(DP+递归)的更多相关文章

  1. poj 1088 dp **

    链接:点我 记忆化搜索很好写 #include<cstdio> #include<iostream> #include<algorithm> #include< ...

  2. POJ 1088 DP=记忆化搜索

    话说DP=记忆化搜索这句话真不是虚的. 面对这道题目,题意很简单,但是DP的时候,方向分为四个,这个时候用递推就好难写了,你很难得到当前状态的前一个真实状态,这个时候记忆化搜索就派上用场啦! 通过对四 ...

  3. POJ 1088 滑雪(记忆化搜索+dp)

    POJ 1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 107319   Accepted: 40893 De ...

  4. POJ 1088 滑雪(记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description ...

  5. poj 1088 滑雪(区间dp+记忆化搜索)

    题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程 ...

  6. poj 1088 滑雪 DP(dfs的记忆化搜索)

    题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...

  7. POJ - 1088 滑雪 dp

    http://bailian.openjudge.cn/practice/1088?lang=en_US 题解: 设一个dp[N][N]数组代表从(i,j)坐标开始能滑到的最远距离.更新的方法为 遍历 ...

  8. poj 1141 区间dp+递归打印路径

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30383   Accepted: 871 ...

  9. DP:Skiing(POJ 1088)

     北大教你怎么滑雪 题目是中文的,要读懂题目其实不难 其实这道题挺经典的,我们这样想,他最终要找到一个最大值,这个时候我们就想到要用动态规划 那怎么用呢?我们同时这样想,由于滑雪的最高点我们不能立马找 ...

随机推荐

  1. redis5.0.4-cluster集群搭建及jedis客户端操作

    一.去官网下载redis5.0 https://redis.io/download 然后解压安装 $ .tar.gz $ cd redis- $ make 二.准备配置文件 打开redis-5.0.4 ...

  2. Getting Started with Elastic Search in .NET

    I have been working on many application during my career.  Many if not all had some searching capabi ...

  3. java_对象序列化

    对象序列化(serializable) 序列化读:ObjectInputStream  ois=new ObjectInputStream(new FileInputStream("./gg ...

  4. Xcode升级到9.3之后pod问题

    最近新建了一个项目,然后在终端pod init的时候出现了问题,复制粘贴部分错误信息 MacBook-Pro:testDemo xywy$ pod init [in /Users/xywy/Deskt ...

  5. Es6 类class的关键 super、static、constructor、new.target

    ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...

  6. POJ 2196

    #include <iostream> using namespace std; int sum_10; int sum_12; int sum_16; int fun_10(int nu ...

  7. JS对Date的扩展,将 Date 转化为指定格式的String

    /** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) 可以用 1-2 个占位符 * ...

  8. 【算法笔记】A1063 Set Similarity

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

  9. [转] 如何在 CentOS7 中使用阿里云的yum源

    [From] https://www.cnblogs.com/lpbottle/p/7875400.html 1. 备份原来的yum源 mv /etc/yum.repos.d/CentOS-Base. ...

  10. anyncTask的3个参数(从源码可以发现其中使用了ThreadPoolExcuter线程池)

    AnyncTask异步处理数据并将数据应用到视图的操作场合 一  其中包含这几个方法 1 onPreExcute() 初始化控件,例如进度条2 doInBackground() 具体的执行动作请求数据 ...