codevs 2152 滑雪

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

输入描述 Input Description
输入文件 第1行: 两个数字r,c(1<=r,c<=100),表示矩阵的行列。 第2..r+1行:每行c个数,表示这个矩阵。

输出描述 Output Description
输出文件
仅一行: 输出1个整数,表示可以滑行的最大长度。

样例输入 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

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dt[233][233];
int r, c;
int dpss[233][233];
const int fk = 214748364;

int search(int x, int y, int s)
{
    if(dpss[x][y] && dt[x][y] != fk)
        return dpss[x][y];
    if(dt[x][y] > dt[x-1][y])
        dpss[x][y] = max(dpss[x][y], s + search(x-1, y, 1));
    if(dt[x][y] > dt[x][y-1])
        dpss[x][y] = max(dpss[x][y], s + search(x, y-1, 1));
    if(dt[x][y] > dt[x+1][y])
        dpss[x][y] = max(dpss[x][y], s + search(x+1, y, 1));
    if(dt[x][y] > dt[x][y+1])
        dpss[x][y] = max(dpss[x][y], s + search(x, y+1, 1));    
    return  dpss[x][y];
}

int main()
{
    scanf("%d%d", &r, &c);
    for(int i = 0; i <= r+1; i++)
        for(int j = 0; j <= c+1; j++)
            dt[i][j] = fk;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
        {
            scanf("%d", &dt[i][j]);
        }
    int ans = 0;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
        {
            if(!dpss[i][j])
                dpss[i][j] = search(i, j, 1);
            ans = max(ans, dpss[i][j]);
        }

    printf("%d", ans + 1);
    return 0;
}

转载于:https://www.cnblogs.com/Loi-Vampire/p/6017065.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值