poj 1088(记忆化搜索)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 88560 | Accepted: 33212 |
Description
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
Input
Output
Sample Input
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Sample Output
25
Source
以前真是太水了。。竟然是看了解题报告觉得好神奇 前几个月的咸鱼,现在叫菜鸟吧2333
重写一遍,一个记忆化搜索的基础题。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
int mp[N][N];
int dp[N][N]; ///dp[i][j]保存的是当前点能划最远的距离
int n,m;
int dir[][] ={{,},{-,},{,},{,-}};
int dfs(int x,int y){
int ans = ;
if(dp[x][y]>) return dp[x][y]; ///记忆化搜索:已经搜过剪枝
for(int i=;i<;i++){
int nextx = x+dir[i][];
int nexty = y+dir[i][];
if(nextx<||nextx>n||nexty<||nexty>m) continue;
if(mp[nextx][nexty]<mp[x][y]){
ans = max(ans,dfs(nextx,nexty));
}
}
dp[x][y]=ans+; ///子问题的解加上1就是当前点的解
return dp[x][y];
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%d",&mp[i][j]);
dp[i][j] = ; ///初始化每个点的高度为自身
}
int ans = -;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dfs(i,j);
if(dp[i][j]>ans) ans = dp[i][j];
}
}
printf("%d\n",ans);
} }
poj 1088(记忆化搜索)的更多相关文章
- 滑雪(POJ 1088 记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 88094 Accepted: 33034 Description ...
- POJ 1191 记忆化搜索
(我是不会告诉你我是抄的http://www.cnblogs.com/scau20110726/archive/2013/02/27/2936050.html这个人的) 一开始没有想到要化一下方差的式 ...
- Test for Job (poj 3249 记忆化搜索)
Language: Default Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 9733 A ...
- POJ 2704 Pascal's Travels 【DFS记忆化搜索】
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS Memory Limit: 65536K Tota ...
- POJ 1579 Function Run Fun 【记忆化搜索入门】
题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Tota ...
- 专题1:记忆化搜索/DAG问题/基础动态规划
A OpenJ_Bailian 1088 滑雪 B OpenJ_Bailian 1579 Function Run Fun C HDU 1078 FatMouse and Chee ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 1088 滑雪 DFS 记忆化搜索
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...
- POJ 1088 滑雪【记忆化搜索】
题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已 ...
随机推荐
- async的基本用法
1. async函数的基本形式 //函数声明 async function foo() {} //函数表达式 const foo = async function () {}; //对象的方法 let ...
- java oracle clob string 大字符串存储【转】
单位用到了oracle存储string类型到数据库里的clob,上网查看资料找到解决方案.如下: public class ClobTest { static String url = "j ...
- input file上传图片预览,非插件
Input标签 <input type="file" name="pic" onchange="changepic(this)" mu ...
- lightoj 1282 && uva 11029
Leading and Trailing lightoj 链接:http://lightoj.com/volume_showproblem.php?problem=1282 uva 链接:http:/ ...
- 在windows下如何使用密钥对远程登录服务器?
在企业的生产中相信各位朋友都会使用远程登录服务器,这样即高效也非常方便,(服务器在西藏,没有远程技术,公司在北京,你只能到西藏与机器相伴,在这里我使用xshell软件),我们使用ssh 服务登录服务器 ...
- POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- 【BZOJ4869】相逢是问候 [线段树][欧拉定理]
相逢是问候 Time Limit: 40 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description Informatikverbin ...
- 「6月雅礼集训 2017 Day4」寻找天哥
[题目大意] 给出$n$个三维向量,设当前向量长度为$L$,每次沿着向量等概率走$[0,L]$个长度.一个球每秒半径增加1个长度,直到覆盖位置,每秒耗能为球体积,求总耗能的期望. 设最后半径为R,那么 ...
- 【bzoj】1717 [Usaco2006 Dec]Milk Patterns 产奶的模式
[算法]后缀数组 [题解]后缀数组 由于m太大,先离散化. 然后处理SA和LCP. 最后用单调队列处理即可. 注意实际上队列头尾长度限制是K-1. 删队尾不要删过头 i≥K才能开始统计答案. #inc ...
- Html5学习2(Html表格、Html列表、Html5新元素、Canvas (坐标、路径、画圆、文本、渐变、图像))
Html表格 1.表格中的表头:<th></th>.其中表头部分字体加粗,颜色深绿色 <h4>水平标题:</h4> <table border=& ...