haohaohaohao @ 2020-01-15 16:44:16
#include<stdio.h>
#include<iostream>
using namespace std;
int map[102][102],N,M,next[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int recoder[102][102];
int dfs(int x,int y)
{
if(recoder[x][y])
return recoder[x][y];
int max = 1;
for(int i = 0;i<4;i++)
{
int x_n = x+next[i][0];
int y_n = y+next[i][1];
if(map[x_n][y_n]&&map[x_n][y_n]<map[x][y])
{
int t = dfs(x_n,y_n)+1;
if(t>max)
max = t;
}
}
if(max>recoder[x][y])
recoder[x][y] = max;
return max;
}
int main()
{
cin>>N>>M;
for(int i = 1;i<=N;i++)
for(int j = 1;j<=M;j++)
cin>>map[i][j];
int max = 1;
for(int i = 1;i<=N;i++)
for(int j = 1;j<=M;j++)
{
int t = dfs(i,j);
if(t>max)
max = t;
}
cout<<max<<endl;
return 0;
}
by love_a_horse @ 2020-03-11 23:38:42
我和你一模一样都是5和7WA
by love_a_horse @ 2020-03-11 23:52:16
我知道了,是因为最低的可能比1小