#include<stdio.h>
int MaxTime(int R, int C, int a[100][100], int r,int c)
{
if(a == NULL)
{
return 0;
}
// 上
int result = 1,result1 = 1,result2 = 1,result3 =1,result4 =1;
if((r-1 >= 0 )&&(a[r][c]>a[r-1][c]))
{
result1 = 1 + MaxTime(R,C,a,r-1,c);
result = result1;
}
//下
if((r+1 < R )&&(a[r][c]>a[r+1][c]))
{
result2 = 1 + MaxTime(R,C,a,r+1,c);
if(result < result2)
{
result = result2;
}
}
//左
if((c-1>=0)&&(a[r][c] >= a[r][c-1]))
{
result3 = 1 + MaxTime(R,C,a,r,c-1);
if(result < result3)
{
result = result3;
}
}
//右
if((c+1<C)&&(a[r][c] >= a[r][c+1]))
{
result4 = 1 + MaxTime(R,C,a,r,c+1);
if(result < result4)
{
result = result4;
}
}
return result;
}
int main()
{
int R , C;
scanf("%d %d",&R,&C);
printf("%d %d",R,C);
if(R < 1 || C < 1 || R > 100 || C > 100)
{
return 0;
}
int a[100][100] = {0};
int i,j;
printf("\n");
for(i = 0; i < R;i++)
{
for(j =0;j<C;j++)
{
scanf("%d",&(a[i][j]));
}
printf("\n");
}
printf("\n");
for(i = 0 ;i<R;i++)
{
for(j =0;j<C;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
int result = 0;
for(i = 0;i<R;i++)
{
for(j = 0;j<C;j++)
{
int tmp = MaxTime(R,C,a,i,j);
if(result < tmp)
result = tmp;
}
}
printf("result = %d\n",result);
}
输入:
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
输出:result = 25