poj 1088 滑雪(beta)
来源:互联网 发布:淘宝电动车加热手套 编辑:程序博客网 时间:2024/06/05 05:25
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
SHTSC 2002
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn = 1005;int map[maxn][maxn], len[maxn][maxn];int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};int r,c;int dp(int i,int j){ if(len[i][j]!=0)return len[i][j]; int maxx=0,s; for(int t=0;t<4;t++) { int temx=i+dir[t][0],temy=j+dir[t][1]; if(temx>=0&&temx<r&&temy>=0&&temy<c&&map[temx][temy]<map[i][j]) { s=dp(temx,temy); if(s>maxx)maxx=s; } } len[i][j]=maxx+1; return maxx+1;}int main(){ while(~scanf("%d%d",&r,&c)) { int mx=-1; memset(len,0,sizeof(len)); for(int i=0;i<r;i++) for(int j=0;j<c;j++) scanf("%d",&map[i][j]); for(int i=0;i<r;i++) for(int j=0;j<c;j++) {len[i][j]=dp(i,j); if(len[i][j]>mx)mx=len[i][j]; } /* for(int i=0;i<r;i++) { for(int j=0;j<c;j++) printf("%d ",len[i][j]); printf("\n");}*/ printf("%d\n",mx); } return 0;}
0 0
- poj 1088 滑雪(beta)
- POJ 1088(滑雪)
- 滑雪(POJ-1088)
- POJ 1088 滑雪(DP)
- POJ 1088 滑雪(dp)
- poj - 1088 - 滑雪(dp)
- POJ 1088 滑雪 (dp)
- POJ 1088 滑雪(DP)
- POJ 1088 滑雪 (深搜)
- POJ 1088 滑雪(dp)
- POJ 1088 滑雪 (DP)
- H-滑雪(POJ 1088)
- POJ 1088 滑雪(dp)
- poj 1088滑雪 (动态规划)
- POJ 1088滑雪(dfs的方法)
- POJ 1088 滑雪(动态规划经典)
- poj 1088 滑雪(贪心算法)
- poj 1088 滑雪(简单dfs)
- CSDN-markdown编辑器语法总结
- http://www.cnblogs.com/exmyth/p/4555814.html
- XML基本语法
- 自组织网络(Ad hoc)
- python xlsxwriter创建excel图表
- poj 1088 滑雪(beta)
- uc/os II读书笔记(2)
- Leetcode-34. Search for a Range
- POJ-2736 Housewife Wind(树链剖分)
- VHDL快速入门一
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 运行结果展示方法
- 独立编址与统一编址
- 机房收费系统——组合窗体