primaryzk @ 2021-03-31 22:41:40
#include<stdio.h>
int r, c, i, j, max=0;
int a[110][110], s[110][110];
int road(int x, int y){
if (s[x][y])
return s[x][y];
s[x][y] = 1;
if (y-1>0&&a[x][y]>a[x][y-1]){
road(x, y-1);
if (s[x][y-1]+1>s[x][y])
s[x][y] = s[x][y-1]+1;
}
if (y+1<=r&&a[x][y]>a[x][y+1]){
road(x, y+1);
if (s[x][y+1]+1>s[x][y])
s[x][y] = s[x][y+1]+1;
}
if (x-1>0&&a[x][y]>a[x-1][y]){
road(x-1, y);
if (s[x-1][y]+1>s[x][y])
s[x][y] = s[x-1][y]+1;
}
if (x+1<=c&&a[x][y]>a[x+1][y]){
road(x+1, y);
if (s[x+1][y]+1>s[x][y])
s[x][y] = s[x+1][y]+1;
}
return s[x][y];
}
int main(){
scanf("%d %d", &r, &c);
for (i=1;i<=r;i++)
for (j=1;j<=c;j++)
scanf("%d", &a[i][j]);
for (i=1;i<=r;i++)
for (j=1;j<=c;j++)
if (max<road(i, j))
max = road(i, j);
printf("%d", max);
}
by metaphysis @ 2021-04-01 07:55:30
@primaryzk
行和列搞反了。
if (y+1<=r&&a[x][y]>a[x][y+1])
if (x+1<=c&&a[x][y]>a[x+1][y])
=>
if (y+1<=c&&a[x][y]>a[x][y+1])
if (x+1<=r&&a[x][y]>a[x+1][y])
by primaryzk @ 2021-04-01 21:54:15
@metaphysis 谢谢大佬