JiuZhE66666 @ 2023-09-23 13:46:27
#include<stdio.h>
int n,m;
int x1[4]={0,0,1,-1},y1[4]={1,-1,0,0};
int hill[105][105]={0};
int height[105][105]={0};
int maxs=0;
void ss(int x,int y,int len)
{
height[x][y]=len;
if(len>maxs)maxs=len;
for(int i=0;i<4;i++)
{
int x2=x+x1[i],y2=y+y1[i];
if(hill[x2][y2]<=hill[x][y]&&x2>=1&&x2<=n&&y2>=1&&y2<=m&&len+1>height[x2][y2])ss(x2,y2,len+1);
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)scanf("%d",&hill[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
int tallest=1;
for(int l=0;l<4;l++)
{
int x2=i+x1[l],y2=j+y1[l];
if(x2>=1&&x2<=n&&y2>=1&&y2<=m)
if(hill[i][j]<hill[x2][y2]||height[x2][y2]>=2)tallest=0;
}
if(tallest) ss(i,j,1);
}
printf("%d",maxs);
return 0;
}
by abcaawtq @ 2023-09-23 22:51:20
把
if(hill[x2][y2]<=hill[x][y]&&x2>=1&&x2<=n&&y2>=1&&y2<=m&&len+1>height[x2][y2])ss(x2,y2,len+1);
改成
if(hill[x2][y2]<hill[x][y]&&x2>=1&&x2<=n&&y2>=1&&y2<=m&&len+1>height[x2][y2])ss(x2,y2,len+1);
by abcaawtq @ 2023-09-23 22:51:49
实测AC
by abcaawtq @ 2023-09-23 22:55:09
@JiuZhE66666
by JiuZhE66666 @ 2023-09-24 11:44:37
@abcaawtq 感谢!