POJ 1088 滑雪
来源:互联网 发布:淘宝禁止好评返现2016 编辑:程序博客网 时间:2024/05/01 01:13
题目大意:
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道在一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子
1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
输入:
输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。
输出:
输出最长区域的长度。
解题思路:
这是一道简单的动态规划题,用动态规划思想解决。
用二维数组a[100][100]表示区域,定义状态s[i][j]表示从a[i][j]开始滑行能够滑行的最大长度。
状态转移方程s[i][j]=max{s[i-1][j], s[i+1][j], s[i][j-1], s[i][j+1]}+1,下标不能越界并且四个相邻点的高度要比a[i][j]小。
计算所有s[i][j],输出s[i][j]的最大值。
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#define N 101using namespace std;int map[N][N],len[N][N];int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};int r,c,i,j;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 max=-1; memset(len,0,sizeof(len)); for(i=0;i<r;i++)for(j=0;j<c;j++)scanf("%d",&map[i][j]);for(i=0;i<r;i++)for(j=0;j<c;j++){len[i][j]=dp(i,j);if(len[i][j]>max)max=len[i][j];}printf("%d\n",max); }}
0 0
- POJ 1088 滑雪
- POJ 1088 滑雪
- POJ 1088 滑雪
- Poj 1088 滑雪
- poj 1088 滑雪
- 滑雪--POJ--1088
- poj 1088 滑雪(DP)
- POJ 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪 DP
- POJ 1088 滑雪
- Poj 1088 滑雪
- jdk配置
- 喷水装置(一)
- JAVA数据类型
- 多态
- 杭电 3785 寻找大富翁
- POJ 1088 滑雪
- Eclipse 一直提示 loading descriptor for 的解决方法
- 2015多校第一场1003 hdu 5290 Bombing plan
- linux系统中定义的信号
- OC_block
- hdoj 1873看病要排队 【队列】
- DOM对象的小程序
- swift2 运算符函数
- hibernate 一级缓存