覃常锟 @ 2020-02-24 13:12:57
RT
不知道为什么这道题下载不了测试用例,
自己编了很多测试用例了,都没错,实在想不出来错哪了
by 淡看云卷云舒 @ 2020-02-24 13:17:49
@jsbdzzfsj
有的题目是不能下样例的
by 淡看云卷云舒 @ 2020-02-24 13:18:10
@jsbdzzfsj
不过这道题挺简单的
私信发我代码吧
by 淡看云卷云舒 @ 2020-02-24 13:18:26
@jsbdzzfsj
我给你看看或者告诉你正确的思路
by 覃常锟 @ 2020-02-24 13:20:11
@淡看云卷云舒
好的,谢谢了
by 覃常锟 @ 2020-02-24 13:22:04
@淡看云卷云舒
#include<iostream>
using namespace std;
int n, m, Max = 0, l[100][100] = { 0 }, high[100][100] = { 0 }, dire[4][2] = { -1,0,0,1,1,0,0,-1 };//xy标记高度为i的坐标,横坐标为值/m纵坐标为值%m
void DFS(int x, int y, int deep)
{
int i, dx, dy, temp = 0;//temp表示周边已遍历的点的最大深度
if (deep > Max)
{
//cout << "深度到了" << deep << endl;
Max = deep;
}
for (i = 0; i < 4; i++)
{
dx = dire[i][0], dy = dire[i][1];
if (x + dx >= 0 && x + dx < n && y + dy >= 0 && y + dy < m && high[x + dx][y + dy] < high[x][y])//判断该点可达
{
if (l[x + dx][y + dy] == 0)
{
DFS(x + dx, y + dy, deep + 1);
}
if (l[x + dx][y + dy] > temp)//该点的某个邻点已经遍历过,有记忆数据,记录该点最大的邻点深度
{
temp = l[x + dx][y + dy];
}
}
}
if (Max - deep >= temp)
l[x][y] = Max - deep + 1;
else l[x][y] = temp + 1;
}
int main()
{
int i, j, k, p;
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
cin >> high[i][j];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
Max = 0;
//cout << "i,j=(" << i << "," << j << ")开始了" << endl;
if (l[i][j] == 0)
DFS(i, j, 0);
/*k = i, p = j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
cout << l[i][j] << " ";
cout << endl;
}
cout << endl;
i = k, j = p;*/
}
}
Max = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (l[i][j] > Max) Max = l[i][j];
cout << Max;
return 0;
}
by 淡看云卷云舒 @ 2020-02-24 13:22:30
@jsbdzzfsj
私信说吧
by 覃常锟 @ 2020-02-24 13:24:08
@淡看云卷云舒
我找不到私信的选项QAQ,只有屏蔽、关注和动态
by 淡看云卷云舒 @ 2020-02-24 13:25:23
@jsbdzzfsj
右上角头像左边两个有一个信封装的图标