Day2-N-滑雪-POJ1088
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 分析:记忆化搜索+DFS即可,代码如下:
const int maxm = ;
const int dx[] = {-, , , };
const int dy[] = {, , -, }; int r, c, d[maxm][maxm], G[maxm][maxm]; bool inside(int x,int y) {
return x >= && x < r && y >= && y < c;
} int dfs(int x,int y) {
if(d[x][y])
return d[x][y];
d[x][y] = ;
for(int i = ; i < ; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if(inside(nx,ny) && G[x][y] < G[nx][ny]) {
d[x][y] = max(d[x][y], dfs(nx, ny) + );
}
}
return d[x][y];
} int main() {
scanf("%d%d", &r, &c);
for (int i = ; i < r; ++i) {
for (int j = ; j < c; ++j)
scanf("%d", &G[i][j]);
}
int res = ;
for (int i = ; i < r; ++i) {
for (int j = ; j < c; ++j) {
if(!d[i][j])
res = max(res, dfs(i, j));
}
}
printf("%d\n", res);
return ;
}
Day2-N-滑雪-POJ1088的更多相关文章
- 滑雪---poj1088(动态规划+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 有两种方法 一是按数值大小进行排序,然后按从小到大进行dp即可: #include <iostream> #incl ...
- dp例题02. 滑雪问题 (poj1088)
poj1088滑雪问题 题目链接:http://poj.org/status Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得 ...
- 【poj1088】 滑雪
http://poj.org/problem?id=1088 (题目链接) 题意 给出一个矩阵,任意选择一个起点,每次只能向周围4个格子中的值比当前格子小的格子移动,求最多能移动多少步. Soluti ...
- 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 ...
随机推荐
- Python爬虫:urllib库的基本使用
请求网址获取网页代码 import urllib.request url = "http://www.baidu.com" response = urllib.request.ur ...
- 在xwindows界面中切换KDE与GNOME
在xwindows界面中切换KDE与GNOME 方法1: 在xwindows界面下通过菜单来切换,找到所需的菜单后执行,选择所需的桌面,重新启动xwindows即可. 方法2: 在命令提示符在xwin ...
- request库解析中文
官网地址: http://cn.python-requests.org/zh_CN/latest/ 高级用法 本篇文档涵盖了 Requests 的一些高级特性. 会话对象 会话对象让你能够跨请求保持某 ...
- redhat7.6 httpd配置php模块
1.安装php yum install "*php*" -y 2.编辑httpd.conf配置文件 找到LoadModule foo_module modules/mod_fo ...
- Python 基础之面向对象之八步理解装饰器
装饰器:在不改变原有代码的情况下,为该原函数扩展新功能特征:返回新函数,替换旧函数语法:@ 语法糖 1.装饰器原型 #例1: def kuozhan(func): def newfunc(): ...
- “数据接口请求异常:error”,Layui-table使用遇到的最大一个坑
后台返回的json格式必须和官方给的一模一样 code必须为0, code必须为0, code必须为0, code必须为0
- 什么是 SDK?
通俗而言: 1.其实很简单,SDK 就是 Software Development Kit 的缩写,中问意思是: 软件开发工具包. 2.这是一个覆盖面相当广泛的名词,可以这么说: 辅助开发某一类软件的 ...
- Spring报错汇总笔记
报错信息: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing X ...
- spring boot 中 2.X 的跨域请求
解决跨域: @Configuration @EnableAutoConfiguration public class ZooConfiguration { @Bean public FilterReg ...
- docker进入交互界面
进入cmd交互界面 docker run -it python:3.5 /bin/bash 退出 exit ctrl + d