zoukankan      html  css  js  c++  java
  • tyvj1004 滑雪

    描述

        trs喜欢滑雪。他来到了一个滑雪场,这个滑雪场是一个矩形,为了简便,我们用r行c列的矩阵来表示每块地形。为了得到更快的速度,滑行的路线必须向下倾斜。
        例如样例中的那个矩形,可以从某个点滑向上下左右四个相邻的点之一。例如24-17-16-1,其实25-24-23…3-2-1更长,事实上这是最长的一条。

    输入格式

    输入文件

    第1行: 两个数字r,c(1<=r,c<=100),表示矩阵的行列。
    第2..r+1行:每行c个数,表示这个矩阵。

    输出格式

    输出文件

    仅一行: 输出1个整数,表示可以滑行的最大长度。

    测试样例1

    输入

    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

    输出

    25
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn = 105;
    int r,c,ans;
    int h[maxn][maxn],f[maxn][maxn];
    int dx[4] = {-1,0,1,0};
    int dy[4] = {0,-1,0,1};
    bool jud(int i,int j){
        if(i < 1 || i > r || j < 1 || j > c) return false;
        return true;
    }
    int dp(int i,int j){
        if(f[i][j]) return f[i][j];
        f[i][j] = 1;
        int y,x;
        for(int t = 0;t < 4;t++){
            y = i + dy[t];
            x = j + dx[t];
            if(jud(y,x) && h[i][j] > h[y][x]) f[i][j] = max(f[i][j],1 + dp(y,x));
        }
        return f[i][j];
    }
    int main(){
        cin>>r>>c;
        for(int i = 1;i <= r;i++){
            for(int j = 1;j <= c;j++){
                cin>>h[i][j];
            }
        }
        for(int i = 1;i <= r;i++){
            for(int j = 1;j <= c;j++){
                ans = max(ans,dp(i,j));
            }
        }
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    linux下shell显示-bash-4.1#不显示路径解决方法
    update chnroute
    An error "Host key verification failed" when you connect to other computer by OSX SSH
    使用dig查询dns解析
    DNS被污染后
    TunnelBroker for EdgeRouter 后记
    mdadm详细使用手册
    关于尼康黄的原因
    Panda3d code in github
    Python实例浅谈之三Python与C/C++相互调用
  • 原文地址:https://www.cnblogs.com/hyfer/p/5754620.html
Copyright © 2011-2022 走看看