2216: Ski

2216: Ski


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
8s8192K853216Special Test

It is well-known that in the game of ski sportsmen slide from a higher position to a lower one, and they always desist when all the abutting (up, down, left, and right) positions are higher. In this problem, you are given a clearing to determine the longest course that can be used for skiing.

Input

Each input file contains only ONE test case, but there might be many input files. Each test case begins with two integers R (<=100) and C (<=100), representing the number of rows and columns of the clearing, which is always a rectangle indicated by a two-dimensional array here. And from the second line there follows R lines, each consisting of C integers, each of which represents the altitude of a position of the clearing, and it is not hard to infer that the larger the integer is the higher the position the integer represents is.

Output

For each test case, print the length of the longest course, the number of transitions, in a single line.

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

Notice: The beginning position of the course is haphazard.

 


This problem is used for contest: 31  147  148 

 

 

#include<iostream>
#include<algorithm>
using namespace std;
int a[105][105],val[105][105];
int r,c;
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
int  dfs(int x,int y)
{
    if(val[x][y]!=-1) return val[x][y];
    int i;
    int m=0;
    for(i=0;i<4;i++)
    {
        if(x+xx[i]<=0||x+xx[i]>r||y+yy[i]<=0||y+yy[i]>c) continue;
        if(a[x][y]>a[x+xx[i]][y+yy[i]])
        {
            int temp=dfs(x+xx[i],y+yy[i]);
            if(temp>m) m=temp;
        }
    }
    val[x][y]=m+1;
    return val[x][y];
}
int main()
{
    int i,j;
    while(scanf("%d%d",&r,&c)==2)
    {
        for(i=1;i<=r;i++) for(j=1;j<=c;j++) {scanf("%d",&a[i][j]);val[i][j]=-1;}
        int  maxn=1;
        for(i=1;i<=r;i++)
        {
            for(j=1;j<=c;j++)
            {
                int t=dfs(i,j);
                if(maxn<t) maxn=t;
            }
        }
        printf("%d/n",maxn);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值