二维数组




#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值