Cris @ 2017-12-03 22:36:26
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int r,c,a[100][100],dir[4][2]={1,0,-1,0,0,1,0,-1},team[500000][3];
//bool visit[100][100];
int bfs(int x,int y){
int head=0,tail=0,maxn=1;
team[0][0]=x;team[0][1]=y;team[0][2]=1;
while(head<=tail){
for(int i=0;i<4;i++){
int kx=team[head][0],ky=team[head][1];
int dx=team[head][0]+dir[i][0],dy=team[head][1]+dir[i][1];
if(dx>=0&&dx<r&&dy>=0&&dy<c&&a[kx][ky]>a[dx][dy]){
tail++;
// visit[dx][dy]=1;
team[tail][0]=dx;
team[tail][1]=dy;
team[tail][2]=team[head][2]+1;
if(team[tail][2]>maxn)maxn=team[tail][2];
}
}
head++;
}
return maxn;
}
int main(){
int e,maxx=0;
cin>>r>>c;
for(int i=0;i<r;i++){
for(int h=0;h<c;h++){
cin>>a[i][h];
}
}
for(int i=0;i<r;i++){
for(int h=0;h<c;h++){
e=bfs(i,h);
if(e>maxx)maxx=e;
// memset(visit,0,sizeof(visit));
}
}
cout<<maxx;
}
by nitrobenzene @ 2018-01-21 22:00:19
和我错误一样,r和c顺序反了,你改成cin>>c>>r;
就对了(目测其他9组数据是r=c的。。。)