记录编号 122961 评测结果 AAAAAAAAAA
题目名称 登山 最终得分 100
用户昵称 GravatarEzio 是否通过 通过
代码语言 C++ 运行时间 0.031 s
提交时间 2014-09-25 07:59:34 内存使用 0.34 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <ctime>
#define For(st,ed,i) for(int i=st;i<=ed;++i)
#define Fordown(st,ed,i) for(int i=st;i>=ed;--i)
#define start(a,flag) memset(a,flag,sizeof(a));
using namespace std;
typedef long long ll;typedef unsigned int uint; typedef unsigned long long ull;
const int INF=0x7fffffff;
int tu[61][61],vis[61][61];
int n,m,maxn=0;
#define YN(a,b) if(!vis[a][b]&&tu[a][b]>tu[x][y]&&a>0&&a<=n&&b>0&&b<=m)
#define YNN(a,b) if(!vis[a][b]&&tu[a][b]<tu[x][y]&&a>0&&a<=n&&b>0&&b<=m)
int dfs(int x,int y,int deep,int fan)
{//fan处1为上0为下 
    int ans=deep;
    vis[x][y]=1;
    if(fan==1){
        YN(x+1,y){ans=max(ans,dfs(x+1,y,deep+1,1));}
        YN(x,y+1){ans=max(ans,dfs(x,y+1,deep+1,1));}
        YN(x-1,y){ans=max(ans,dfs(x-1,y,deep+1,1));}
        YN(x,y-1){ans=max(ans,dfs(x,y-1,deep+1,1));}
        YNN(x+1,y){ans=max(ans,dfs(x+1,y,deep+1,0));}
        YNN(x,y+1){ans=max(ans,dfs(x,y+1,deep+1,0));}
        YNN(x-1,y){ans=max(ans,dfs(x-1,y,deep+1,0));}
        YNN(x,y-1){ans=max(ans,dfs(x,y-1,deep+1,0));}
    }
    if(fan==0){
        YNN(x+1,y){ans=max(ans,dfs(x+1,y,deep+1,0));}
        YNN(x,y+1){ans=max(ans,dfs(x,y+1,deep+1,0));}
        YNN(x-1,y){ans=max(ans,dfs(x-1,y,deep+1,0));}
        YNN(x,y-1){ans=max(ans,dfs(x,y-1,deep+1,0));}
    }
    vis[x][y]=0;
    return ans;
}
int main(){
    freopen("hike.in","r",stdin);
    freopen("hike.out","w",stdout);
    scanf("%d%d",&n,&m);
    For(1,n,i)For(1,m,j)
        scanf("%d",&tu[i][j]);
    int limit=tu[1][1];
    For(1,n,i)For(1,m,j){
        if(tu[i][j]<limit-800000)continue;
        else{
            int z1=dfs(i,j,1,1);
            if(z1>maxn){maxn=z1;limit=max(limit,tu[i][j]);}
        }
    }
    //搜索为从每个点开始
    cout<<maxn<<endl;
	//system("pause");
    return 0;
}