1 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
25
#include "stdio.h" #include "string.h" #define MAXN 10000+10 #define N 100+10 int area[N][N],state[N][N],r,c; //r行數,c列數 int max(int a,int b,int c,int d){ if(ad?a:d; } int dfs(int x,int y,int front){ //front表示從front高度滑下來 if(x<1 || y<1 || x>r || y>c || front<=area[x][y]) return 0; if(state[x][y]>=0) return state[x][y]; state[x][y]=max(dfs(x-1,y,area[x][y]),dfs(x+1,y,area[x][y]),dfs(x,y-1,area[x][y]),dfs(x,y+1,area[x][y]))+1; return state[x][y]; } int main() { int n,result; scanf("%d",&n); if(n<1) return 0; while(n--){ result=0; scanf("%d %d",&r,&c); memset(state,-1,sizeof(state)); for(int x=1;x<=r;x++){ for(int y=1;y<=c;y++){ scanf("%d",&area[x][y]); } } for(int x=1;x<=r;x++){ for(int y=1;y<=c;y++){ int temp=dfs(x,y,MAXN); result=result>temp?result:temp; } } printf("%d\n",result); } return 0; }