poj1088滑雪最短路径
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 97281 | Accepted: 36886 |
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 dp[i][j] = max(dp[i-1][j], dp[i+1][j], dp[i][j-1], dp[i][j+1]) + 1;
采用记忆化搜索
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 100 + 5;
int R, C;
int h[maxn][maxn];
int d[maxn][maxn];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1}; int dp(int x, int y)
{
int k, maxd = 0, s;
if (d[x][y] != 0)
return d[x][y]; //搜索过了就不用搜了
for (k = 0; k <= 3; k++)
{
int tx, ty;
tx = x + dx[k];
ty = y + dy[k];
if (tx < 1 || ty < 1 || tx > R || ty > C)
continue;
if (h[x][y] > h[tx][ty]) {
s = dp(tx, ty);
maxd = max(maxd, s);
}
}
d[x][y] = maxd+1; return d[x][y];
} int main()
{
cin >> R >> C;
int i, j, Max = 0; memset(d, 0, sizeof(d));
for (i = 1; i <= R; i++)
for (j = 1; j <= C; j++)
cin >> h[i][j]; for (i = 1; i <= R; i++) {
for (j = 1; j <= C; j++) {
Max = max(Max, dp(i, j));
}
}
cout << Max << endl; return 0;
}
poj1088滑雪最短路径的更多相关文章
- POJ1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- POJ1088滑雪(dp+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86411 Accepted: 32318 Description ...
- POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 84297 Accepted: 31558 Description M ...
- POJ1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- [POJ1088] 滑雪(递归dp)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- POJ-1088 滑雪 (记忆化搜索,dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...
- poj1088 滑雪 解题报告
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 77423 Accepted: 28779 Description ...
- ACM学习历程—POJ1088 滑雪(dp && 记忆化搜索)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- 经典DP问题--poj1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
随机推荐
- jQuery 网页禁止复制
<script type="text/javascript"> $(document).ready(function(){ $('#文本框id') ...
- Android Weekly Notes Issue #310 (Google IO特别篇)
Android Weekly Issue #310 May 20th, 2018 Android Weekly Issue #290 本期既有本次Google IO对于Play Console的更新简 ...
- LightOJ - 1321 Sending Packets —— 概率期望
题目链接:https://vjudge.net/problem/LightOJ-1321 1321 - Sending Packets PDF (English) Statistics Foru ...
- LightOJ - 1038 Race to 1 Again —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1038 1038 - Race to 1 Again PDF (English) Statistics Foru ...
- Module.exports和exports的区别
原文链接: https://www.ycjcl.cc/2017/02/10/module-exportshe-exportsde-qu-bie/ 学习Seajs时,看到了exports.doSomet ...
- 谷歌新操作系统fuchsia
开源地址: https://github.com/fuchsia-mirror
- L91
Make Healthy Choices Easier Options Telling people to change unhealthy behaviors doesn't work. Other ...
- hdu-5816 Hearthstone(状压dp+概率期望)
题目链接: Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- FAQrobot 聊天机器人笔记
follow: https://github.com/ofooo/FAQrobot 这是一个简单的基于问词匹配的自动问答,获取与用户问句Q1最匹配的知识库中的问句Q2,Q2的答案就是Q1的答案. 首 ...
- 「LOJ#10045」「一本通 2.2 练习 1」Radio Transmission (KMP
题目描述 原题来自:BalticOI 2009 给你一个字符串,它是由某个字符串不断自我连接形成的.但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入格式 第一行给出字符串的长度 L,第 ...