小鲤鱼离线记 @ 2021-03-30 09:36:53
#include<stdio.h>
#include <algorithm>
using namespace std;
#define MAX 105
int f[MAX][MAX], dp[MAX][MAX],n = 0, m = 0,sum=0;
int X[] = { 0,0,-1,1};
int Y[] = { 1,-1,0,0};
//判断坐标x,y是否需要被访问
bool judge(int x,int y) {
if (x > n || x<1 || y>m || y < 1)//越界是否
return false;
return true;
}
int DFS(int x, int y) {
int num = 0,tempx=-1,tempy=-1,t1=0,t2=0;
if (dp[x][y]!=0)
{
return dp[x][y];
}
for (int k = 0; k < 4; k++)
{
tempx = x + X[k];
tempy = y + Y[k];
if (judge(tempx,tempy)&&f[tempx][tempy] < f[x][y]&& f[tempx][tempy]>num)
{
num = f[tempx][tempy];
t1 = tempx;
t2 = tempy;
}
}
if (num!=0)
return DFS(t1, t2)+1;
else
return 1;
}
int main() {
int flag = 0;
scanf("%d%d", &n,&m);
for (int i = 1; i <= n; i++){//赋值给二维数组
for (int j = 1; j <=m; j++)
scanf("%d", &f[i][j]);
}
for (int i = 1; i <= n; i++)
for (int j = 1;j <= m;j++) {
if (dp[i][j] == 0)
dp[i][j] = DFS(i, j);
sum = max(sum, dp[i][j]);
}
printf("%d", sum);
}
by qNAN @ 2021-03-30 19:56:54
你跟我写的基本思路一样,我也是1,5,7WA orz