#2TLE #5#7WA 求助

P1434 [SHOI2002] 滑雪

yaoxxx @ 2019-07-24 20:47:21

2TLE,#5#7WA

#include<bits/stdc++.h>
using namespace std;
int r,c;
int a[101][101];
int maxx=0;
int d[][2]={1,0,0,1,-1,0,0,-1};
void dfs(int way,int x,int y){
    if(maxx<way)maxx=way;//cout<<x<<" "<<y<<"\n";
    for(int i=0;i<4;i++){
        int xx=x+d[i][0],yy=y+d[i][1];
        if(xx>0&&xx<=r&&yy>0&&yy<=c)
            if(a[xx][yy]<a[x][y]&&a[xx][yy])dfs(way+1,xx,yy);   
    }
}
int main(){
    cin>>r>>c;
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++)
            cin>>a[i][j];
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++)
            dfs(1,i,j);
    cout<<maxx;
} 

|