zoukankan      html  css  js  c++  java
  • 滑雪

    Total Submissions: 101036   Accepted: 38447

    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

    这样都能搜过去。。。
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 const int maxn=105;
     8 
     9 int n,m;
    10 int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
    11 int map[maxn][maxn],dp[maxn][maxn],vis[maxn][maxn];
    12 
    13 
    14 int DFS(int x,int y){
    15     if(vis[x][y]) return dp[x][y];
    16     for(int i=0;i<4;i++){
    17         int mx=x+dx[i],my=y+dy[i];
    18         if(mx<0||mx>=n||my<0||my>=m) continue;
    19         if(map[x][y]>map[mx][my]) dp[x][y]=max(dp[x][y],DFS(mx,my)+1);
    20     }  
    21     vis[x][y]=true;
    22     return dp[x][y];
    23 }
    24 
    25 int main()
    26 {   cin>>n>>m;
    27     for(int i=0;i<n;i++)
    28         for(int j=0;j<m;j++)
    29             cin>>map[i][j];
    30     memset(dp,0,sizeof(dp));
    31     memset(vis,false,sizeof(vis));
    32     int ans=0;
    33     for(int i=0;i<n;i++)
    34         for(int j=0;j<m;j++)
    35             ans=max(ans,DFS(i,j));
    36     cout<<ans+1<<endl;
    37     return 0;
    38 }
  • 相关阅读:
    phpcms页面替换
    phpcms笔记
    php头像上传预览
    phpcms后台管理
    php写流程管理
    php写留言板
    php人员权限管理(RBAC)
    单例模式
    Effective C++笔记——day01
    C++Primer笔记-----day08
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7609165.html
Copyright © 2011-2022 走看看