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想知道 ...
随机推荐
- Swift语言概览
Swift语言概览 关于 这篇文章简要介绍了苹果于WWDC 2014公布的编程语言--Swift. 前言 在这里我觉得有必要提一下Brec Victor的Invent ...
- java实现二叉树的构建以及3种遍历方法(转)
转 原地址:http://ocaicai.iteye.com/blog/1047397 大二下学期学习数据结构的时候用C介绍过二叉树,但是当时热衷于java就没有怎么鸟二叉树,但是对二叉树的构建及遍历 ...
- java.sql.SQLException: Illegal connection port value '3306:success'
严重: Servlet.service() for servlet jsp threw exceptionjava.sql.SQLException: Illegal connection port ...
- P3746 [六省联考2017]组合数问题
P3746 [六省联考2017]组合数问题 \(dp_{i,j}\)表示前\(i\)个物品,取的物品模\(k\)等于\(r\),则\(dp_{i,j}=dp_{i-1,(j-1+k)\%k}+dp_{ ...
- mini2440 uboot烧写uImage
mini2440下烧写u-boot后,就可以用u-boot烧写linux内核了. 安装mkimage工具: apt-get install u-boot-tools 解压缩官方mini2440 lin ...
- linux 下 监控系统运行状况 命令 dstat
推荐读文:https://linux.cn/article-3215-1.html
- legend2---开发日志14(游戏对用户友好的设计思路)
legend2---开发日志14(游戏对用户友好的设计思路) 一.总结 一句话总结: 不强制,但是激励:比如宗门灵力等级从强制提升到提升宗门和用户的修炼速度 1.丹药有必要做成随机数值么? 没有 1. ...
- Windows内存性能分析(二)性能瓶颈
内存瓶颈: 由于可用内存缺乏导致系统性能下降的现像. (一).相关的性能对象 主要考虑内存的页面操作和磁盘的I/O操作,需要考虑如下性能对象: Memory性能对象: 用于分析整个系统的内存瓶颈问题. ...
- L94
Early-morning births are genetically programmed THE notion that nothing good happens after midnight ...
- u3d 多线程 网络
开启一个线程做网络连接,和接收数据, 用event进行广播 using UnityEngine; using System; using System.Threading; using System. ...