阿尔托莉雅丶 @ 2020-12-12 14:04:04
代码如下::
#include <iostream>
using namespace std;
int memory[200][200];
int map[200][200];
int row, column;
int offx[4] = {1, -1, 0, 0};
int offy[4] = {0, 0, 1, -1};
int dfs(int x, int y)
{
int maxpath = 1;
if(memory[y][x] != 0)
return memory[y][x];
for(int i = 0; i < 4; i++)
{
int dx = x + offx[i];
int dy = y + offy[i];
if(dx >= 0 && dy >= 0 && dx < row && dy < column && map[dy][dx] < map[y][x])
{
maxpath = max(maxpath, dfs(dx, dy) + 1);
}
}
memory[y][x] = maxpath;
return maxpath;
}
int main(void)
{
int ans = 0;
cin >> row >> column;
for(int i = 0; i < column; i++)
{
for(int j = 0; j < row; j ++)
{
cin >> map[i][j];
}
}
for(int i = 0; i < column; i++)
{
for(int j = 0; j < row; j ++)
{
ans = max(dfs(j , i), ans);
}
}
cout << ans;
return 0;
}