OpenJudge/Poj 1088 滑雪
1.链接地址:
bailian.openjudge.cn/practice/1088
http://poj.org/problem?id=1088
2.题目:
- 总Time Limit:
- 1000ms
- Memory Limit:
- 65536kB
- Description
- Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个 区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子
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
- 输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。
- 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
- Don't know
3.思路:
动态规划,先按照高度降序排序,再依次计算
刚开始想当然,以为从最高高度寻找一个路径一定是最长,所以使用了优先队列+广搜,白白WA了一次
4.代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib> using namespace std; struct PATH
{
int x;
int y;
int height;
}; int cmp(const void* a,const void *b)
{
PATH *p1 = (PATH *) a;
PATH *p2 = (PATH *) b;
return p2->height - p1->height;
} int main()
{
//freopen("C://input.txt","r",stdin); int r,c;
cin >> r >> c; int i,j; int **arr_height = new int*[r];
for(i = ; i < r; ++i) arr_height[i] = new int[c]; int **arr_mark = new int*[r];
for(i = ; i < r; ++i)
{
arr_mark[i] = new int[c];
memset(arr_mark[i],,sizeof(int) * c);
} PATH *arr_path = new PATH[r * c]; for(i = ; i < r; ++i)
{
for(j = ; j < c; ++j)
{
cin >> arr_height[i][j];
arr_path[i * c + j].x = j;
arr_path[i * c + j].y = i;
arr_path[i * c + j].height = arr_height[i][j];
}
} qsort(arr_path,r * c,sizeof(PATH),cmp); int idx_x[] = {-,,,};
int idx_y[] = {,,,-}; int res = ;
for(i = ; i < r * c; ++i)
{
//cout << arr_path[i].height << " " << arr_path[i].x << " " << arr_path[i].y << endl; int max = ;
for(j = ; j < ; ++j)
{
int temp_x = arr_path[i].x + idx_x[j];
int temp_y = arr_path[i].y + idx_y[j]; if(temp_x < || temp_x >= c || temp_y < || temp_y >= r) continue; if(arr_height[temp_y][temp_x] > arr_height[arr_path[i].y][arr_path[i].x] && max < arr_mark[temp_y][temp_x])
{
max = arr_mark[temp_y][temp_x];
}
} arr_mark[arr_path[i].y][arr_path[i].x] = max + ;
if(res < max + ) res = max + ;
} cout << res << endl; delete [] arr_path; for(i = ; i < r; ++i) delete [] arr_height[i];
delete [] arr_height; for(i = ; i < r; ++i) delete [] arr_mark[i];
delete [] arr_mark; return ;
}
OpenJudge/Poj 1088 滑雪的更多相关文章
- POJ 1088 滑雪(记忆化搜索+dp)
POJ 1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 107319 Accepted: 40893 De ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 1088 滑雪 【记忆化搜索经典】
题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ 1088 滑雪 -- 动态规划
题目地址:http://poj.org/problem?id=1088 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
- poj 1088 滑雪(区间dp+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程 ...
- POJ 1088 滑雪 (记忆化搜索)
题目链接:http://poj.org/problem?id=1088 题意很好懂,就是让你求一个最长下降路线的长度. dp[i][j]记录的是i j这个位置的最优的长度,然后转移方程是dp[i][j ...
- POJ - 1088 滑雪 dp
http://bailian.openjudge.cn/practice/1088?lang=en_US 题解: 设一个dp[N][N]数组代表从(i,j)坐标开始能滑到的最远距离.更新的方法为 遍历 ...
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- POJ 1088 滑雪 DFS 记忆化搜索
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...
随机推荐
- ECshop模板机制
ECshop模板机制整理 模板机制 近期新项目涉及到ECshop的二次开发,趁此良机正好可以对闻名已久的ECshop系统进行深入了解.要了解一个系统,那么该系统的模板机制就是最重要的一环.相关整理如下 ...
- smarty3--registerPlugin()函数报错问题
smarty版本:smarty3.1.30 registerPlugin错误信息: Notice: Trying to get property of non-object in E:\Joomla\ ...
- 搭建maven+spring+mybatis工程
一.maven 命令搭建web项目 可以参考我之前的一篇博文maven快速入门 1.搭建web工程 mvn archetype:generate -DgroupId=com.yuanmeng.spri ...
- ASP.NET线程与异步
什么是线程? 线程简单来说就是一种数据结构,用来管理这个程序的执行状态,其中包括 1.线程核心对象->寄存器的状态 2.线程环境块,是一块用户模式下的内存,包含线程的异常处理链的头部.线程的局部 ...
- 基于S7-200的PLC对里程轮(增量式码盘)解码的应用
解码模块为JC-11:工业增量式码盘 解码模块,接口简单,易于使用. 应用Step7-MicroWIN编程软件,为S7-200PLC设计本编码盘的应用程序.由于编码盘输出的脉冲信号频 ...
- android学习日记22--Animation动画简介
Animation动画主要有两种:帧动画(Frame Animation)和补间动画(Tween Animation).补间动画主要包括对位置.角度.尺寸等属性的变化,而帧动画则是通过若干帧图片轮流切 ...
- C栈stack
栈是一种 特殊的线性表 栈仅能在线性表的一端进行操作 栈顶(Top):允许操作的一端 栈底(Bottom):不允许操作的一端 Stack的常用操作 创建栈 销毁栈 清空栈 进栈 出栈 获取栈顶元素 ...
- Getting started: A skeleton application
Getting started: A skeleton application In order to build our application, we will start with theZen ...
- multithread synchronization use mutex and semaphore
#include <malloc.h> #include <pthread.h> #include <semaphore.h> struct job { /* Li ...
- [ImportNew]Java中的并发处理
本文来源:http://www.importnew.com/14506.html 这篇文章讨论了Java应用中并行处理的多种方法.从自己管理Java线程,到各种更好几的解决方法,Executor服务. ...