这题状态方程很容易得到: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); }
}

最新文章

  1. 使用C#的反射机制读取类的字段名称及值
  2. 【代码笔记】iOS-短信分享
  3. 在Visio2010中修改默认字体的大小
  4. jython 2.7 b3发布
  5. Java堆
  6. 微信利用PHP创建自定义菜单的方法
  7. 解决mysql中文乱码(总)
  8. JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer
  9. TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议
  10. C对字符串的部分操作
  11. 浏览器扩展系列————异步可插入协议(pluggable protocol)的实现
  12. 漏洞预警 | Apache Struts2 曝任意代码执行漏洞 (S2-045)
  13. Java8学习(3)- Lambda 表达式
  14. Shiro入门这篇就够了【Shiro的基础知识、回顾URL拦截】
  15. Git分支合并冲突解决
  16. js中call()的用法
  17. 「SCOI2015」国旗计划 解题报告
  18. 远程桌面 把explorer关掉了
  19. AlarmManager守护服务和隐藏桌面图标
  20. shell截取字符串的一些简单方法

热门文章

  1. excel冻结窗口
  2. Django2.0 URL配置详解
  3. H01-Linux系统中搭建Hadoop和Spark集群
  4. luogu_1379 八数码难题
  5. springboot第四篇:debug模式开发运用
  6. VUE源代码调试方法
  7. Java NIO学习与记录(六): NIO线程模型
  8. Github如何在本地创建一个空的仓库
  9. 毫秒查询9位数qq号码是否存在-BitMap算法应用
  10. docker pull 私有镜像