解题关键:记忆化搜索

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int d[][],n,m;
int dp[][];
int dir[][]={,,,-,,,-,};
int dfs(int x,int y){
if(dp[x][y]) return dp[x][y];
int ans=;
for(int i=;i<;i++){
int tx=x+dir[i][],ty=y+dir[i][];
if(tx<||tx>=n||ty<||ty>=m) continue;
if(d[tx][ty]<d[x][y]){
ans=max(ans,dfs(tx,ty));
}
}
return dp[x][y]=ans+;
}
int main(){
while(~scanf("%d%d",&n,&m)){
for(int i=;i<n;i++) for(int j=;j<m;j++) scanf("%d",&d[i][j]);
int ans=;
for(int i=;i<n;i++) for(int j=;j<m;j++) ans=max(ans,dfs(i,j));
printf("%d\n",ans);
}
return ;
}

[poj1088]滑雪(二维最长下降子序列)的更多相关文章

  1. SGU 199 Beautiful People 二维最长递增子序列

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20885 题意: 求二维最长严格递增子序列. 题解: O(n^2) ...

  2. dp --- 二维dp + 最大上升子序列

    <传送门> 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 74477   Accepted: 27574 ...

  3. 【最长下降子序列】【动态规划】【二分】XMU 1041 Sequence

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1041 题目大意: 一个二维平面,上面n(n<=1 000 000)个点.问至少选 ...

  4. 低价购买 (动态规划,变种最长下降子序列(LIS))

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  5. 最长下降子序列O(n^2)及O(n*log(n))解法

    求最长下降子序列和LIS基本思路是完全一样的,都是很经典的DP题目. 问题大都类似于 有一个序列 a1,a2,a3...ak..an,求其最长下降子序列(或者求其最长不下降子序列)的长度. 以最长下降 ...

  6. BUY LOW, BUY LOWER_最长下降子序列

    Description The advice to "buy low" is half the formula to success in the bovine stock mar ...

  7. 【最长下降子序列的长度和个数】 poj 1952

    转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...

  8. POJ-1887 Testing the CATCHER(dp,最长下降子序列)

    Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...

  9. ZZNU 1719(最长上升子序列+最长下降子序列)

    先吐血一发,噗! 再吐血一次,啊啊啊啊! 好吧,做了那么多次最长上升子序列,看这题看了半天才发现还有最长下降子序列,呵呵哒! AC代码: #include<stdio.h>//老恶心#in ...

随机推荐

  1. CentOS 6.5 下安装配置GO 1.2.1

    步骤1:保持联网状态,命令 # wget http://go.googlecode.com/files/go1.2.linux-amd64.tar.gz 这里下载的是64位,wget这里默认下载到当前 ...

  2. ubuntu14.04 pygame安装 python2.7

    系统:ubuntu14.04 LTS amd64python版本:2.7.6pygame版本:1.9.1release别这种方法了,这么安装不知道什么原因就出现了问题,在使用pygame.image. ...

  3. 【leetcode刷提笔记】Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  4. Vue mixins extends extend components

    mixins 调用方式: mixins: [mixin1, mixin2] 是对父组件的扩充,包括methods.components.directive等... 触发钩子函数时,先调用mixins的 ...

  5. hadoop启动时解决权限问题

    解决以上问题,使用命令:sudo chown -hR jxh-ubuntu /usr/local/hadoop

  6. vps 虚拟机 云服务器

    vps :wxmp 03服务器 虚拟主机: 万网免费主机 云服务器:wxmp阿里云

  7. java:安装Runtime Environment,设置Tomcat Server 的方法

    Eclipse 中开发Webapp, 一般需要配置Tomcat Server, 以便在Eclipse 中进行Debug.具体的步骤如下: 1. Windows ==>Preference ==& ...

  8. C++(十)— 字符串进行插入、替换、查找、删除操作、substr

     1.C++中对字符串进行插入.替换.删除操作 #include<iostream> #include<algorithm> #include<stdio.h> # ...

  9. C++(八)— 死锁原因及解决方法

    1.死锁原因 死锁问题被认为是线程/进程间切换消耗系统性能的一种极端情况.在死锁时,线程/进程间相互等待资源,而又不释放自身的资源,导致无穷无尽的等待,其结果是任务永远无法执行完成. 打个比方,假设有 ...

  10. unity的一些重要技巧(转)【整理他人的东西】

    刚开始学习Unity3D时间不长,在看各种资料.除了官方的手册以外,其他人的经验也是非常有益的.偶尔看到老外这篇文章,觉得还不错,于是翻译过来和大家共享.原文地址: http://devmag.org ...