#include #include #include typedef struct SKI{ int data; int x; int y; char flag; int len; }STSKI; int compare(const void * i1, const void *i2){ STSKI *a = (STSKI *)i1; STSKI *b = (STSKI *)i2; return (b->data - a->data); } int judgeXY(int X, int Y, int x, int y){ if(x-1 < 0 || x+1 >= X || y-1 < 0 || y+1 > Y) return 0; return 1; } int dfs(int arr[], int size, int x, int y, int len); int main(){ int R, C; int i=0; int j=0; // int arr[]={4,1,3,8,0,2}; // qsort(arr, sizeof(arr)/sizeof(arr[0]), sizeof(arr[0]), compare); // for (int var = 0; var < sizeof(arr)/sizeof(arr[0]); ++var) { // printf("%d ", arr[var]); // } STSKI ski[10000]; memset(&ski, 0x00, sizeof(ski)); //int path[10000]={0}; int X=0; int Y=0; int indexXY=0; scanf("%d%d", &R, &C); for (i = 0; i < R; ++i) { for (j = 0; j < C; ++j) { int a,b; scanf("%d", &a); ski[indexXY].x = i; ski[indexXY].y = j; ski[indexXY].data = a; ski[indexXY].flag = '0'; ski[indexXY].len = 0; ++indexXY; } } // for (i = 0; i < R; ++i) { // for (j = 0; j < C; ++j) { // printf("%d ", ski[i*C+j].data); // } // printf("\n"); // } qsort(ski, R*C, sizeof(ski[0]), compare); // for (i = 0; i < R; ++i) { // for (j = 0; j < C; ++j) { // printf("data:%d x:%d y:%d ", ski[i*C+j].data, ski[i*C+j].x, ski[i*C+j].y); // } // printf("\n"); // } // for (i = 0; i < R; ++i) { // for (j = 0; j < C; ++j) { // printf("data:%d ", ski[i*C+j].data); // } // printf("\n"); // } for(i=0; i<R*C; i++){ ski[i].flag = '1'; if (ski[i].x-1 < 0) { continue; } else if(ski[i].x+1 > R){ continue; }else if (ski[i].y-1 < 0) { continue; }else if (ski[i].y+1 > C) { continue; }else { } // int ret=0; // ret = judgeXY(R, C, ski[i].x, ski[i].y); // x,y:out of range? } return 0; } int dfs(int arr[][], int X, int Y, int x, int y, int len){ return 0; }
// C v0.01 wa
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int dfs(int cur, int x, int y, int X, int Y);
int arr[101][101];
int dep[101][101];
int main(){
int m;
int R, C;
int i=0;
int j=0;
int tmp_MAX=0;
scanf("%d", &m);
getchar();
while(m--){
scanf("%d%d", &R, &C);
getchar();
memset(&arr, 0x00, sizeof(arr));
for (i = 0; i < R; ++i) {
for (j = 0; j < C; ++j) {
scanf("%d", &arr[i][j]);
dep[i][j] = 0;
}
}
for (i = 0; i < R; ++i) {
for (j = 0; j < C; ++j) {
int tmp=0;
if(dep[i][j] == 0){
tmp = dfs(arr[i][j],i, j, R, C);
}else {
tmp = dep[i][j];
}
if(tmp_MAX < tmp){
tmp_MAX = tmp;
}
}
//printf("\n");
}
printf("%d\n", tmp_MAX+1);
}
return 0;
}
int dfs(int cur,int x, int y, int X, int Y){
//dep[x][y]=0,indicates that it hasn't gone through dep(x,y)
if(dep[x][y] == 0){
int max=0;
//before
if(x-1>=0 && cur > arr[x-1][y]){
int tmp = dfs(arr[x-1][y],x-1,y,X,Y);
if(max < tmp+1) max = tmp+1;
}
//after
if(x+1<X && cur > arr[x+1][y]){
int tmp = dfs(arr[x+1][y],x+1,y,X,Y);
if(max < tmp+1) max = tmp+1;
}
//left
if(y-1>=0 && cur > arr[x][y-1]){
int tmp = dfs(arr[x][y-1],x,y-1,X,Y);
if(max < tmp+1) max = tmp+1;
}
//right
if(y+1<Y && cur > arr[x][y+1]){
int tmp = dfs(arr[x][y+1],x,y+1,X,Y);
if(max < tmp+1) max = tmp+1;
}
dep[x][y] = max;
return max;
}else {
return dep[x][y];
}
}