• BNUOJ 1207 滑雪


    滑雪

    1000ms
    65536KB
     
    This problem will be judged on PKU. Original ID: 1088
    64-bit integer IO format: %lld      Java class name: Main
     
    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

     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <vector>
     6 #include <climits>
     7 #include <ctype.h>
     8 #include <cmath>
     9 #include <algorithm>
    10 #define LL long long
    11 using namespace std;
    12 int rows,cols;
    13 int table[101][101],rec[101][101];
    14 int solve(int x,int y,int height){
    15     if(x < 0 || y < 0 || x >= rows || y >= cols || table[x][y] <= height)
    16         return 0;
    17     if(rec[x][y]) return rec[x][y];
    18     rec[x][y] = max(rec[x][y],solve(x-1,y,table[x][y]));
    19     rec[x][y] = max(rec[x][y],solve(x+1,y,table[x][y]));
    20     rec[x][y] = max(rec[x][y],solve(x,y+1,table[x][y]));
    21     rec[x][y] = max(rec[x][y],solve(x,y-1,table[x][y]));
    22     return ++rec[x][y];
    23 }
    24 int main(){
    25     int i,j,mx,temp;
    26     scanf("%d %d",&rows,&cols);
    27         for(i = 0; i < rows; i++){
    28             for(j = 0; j < cols; j++){
    29                 scanf("%d",table[i]+j);
    30                 rec[i][j] = 0;
    31             }
    32         }
    33         for(mx = i = 0; i < rows; i++){
    34             for(j = 0; j < cols; j++){
    35                 temp = solve(i,j,INT_MIN);
    36                 if(temp > mx) mx = temp;
    37             }
    38         }
    39         printf("%d
    ",mx);
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    404. 左叶子之和
    112. 路径总和
    110. 平衡二叉树
    513. 找树左下角的值
    博客第一天
    博客开通第七天
    博客第二天
    超级实用且不花哨的js代码大全
    利用OleDb的GetOLEDBSchemaTable方法得到数据库架构信息.NET教程,数据库应用
    实现给定一个数据库连接得到数据库下所有的数据表
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3835738.html
Copyright © 2020-2023  润新知