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想知道 ...
随机推荐
- python数据分析之:数据清理,转换,合并,重塑(二)
一:移除重复数据 DataFrame经常出现重复行,就像下面的这样 In [7]: data=DataFrame({'k1':['one']*3+['two']*4,'k2':[1,1,2,3,3,4 ...
- 在tomcat下直接访问Html报错,说找不到资源(404)
今天由于工作需要,想把一个html直接放到tomcat(干净的tomcat,没有做过任何修改.)下进行访问,然后根据经验就直接在webapps下创建了个文件夹test,然后把需要的test.html拷 ...
- linux日志系统介绍 —— syslog(),openlog(),closelog()
函数使用介绍 这里面的三个函数openlog, syslog.closelog是一套系统日志写入接口.另外那个vsyslog和syslog功能一样,仅仅是參数格式不同. 通常.sysl ...
- API的理解和使用——列表类型的命令
列表类型的命令及对应的时间复杂度 操作 命令 功能 时间复杂度 添加 rpush key value [value ...] 向右插入 O(k),k是元素个数 lpush key value [val ...
- lucene内置的评分函数
For multiterm queries, Lucene takes the Boolean model, TF/IDF, and the vector space model and combin ...
- swift的泛型貌似还差点意思
protocol Container { typealias ItemType mutating func append(item: ItemType) mutating func removelas ...
- WEB攻击之 CSRF 攻击及防御策略
介绍 是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法. 释义: 跨站请求攻击,简单地说,是攻击者通过一些技术手段欺骗用户的浏览器去访问一个自己曾经认证过的网站并运行一些操作(如 ...
- WC2017 冬眠记
2017年2月3日,为期7天的冬眠营冬令营正式开幕. 前4天我们见到了各种集训队dalao们的华丽身姿 感受到了听课听不懂睡觉又惭愧的无力感 见到了几百号人近一半玩手机,剩下的一半有一半在睡觉,再剩下 ...
- mysql建表练习
create table class( cid int primary key auto_increment, caption ) not null )engine=innodb; create ta ...
- TI官网常用链接
TMS320C6000系列DSP库dsplib下载 TMS320C6000系列DSP库imglib下载 TMS320C6000系列DSP库mathlib下载 TMS320C66657技术文档