m泛函625 @ 2022-01-26 20:49:35
求助大佬们第二个点
#include<iostream>
#include<string.h>
using namespace std;
int ans[105][105],map[105][105],m,n,res;
int movex[4] = { -1,0,1,0 }, movey[4] = {0,1,0,-1};
int dfs(int i, int j) {
if (ans[i][j] != -1) {
return ans[i][j];
}
for (int k = 0; k < 4; ++k) {
int posx = i + movex[k], posy = j + movey[k];
if (posx >= 0 && posx < m && posy >= 0 && posy < n && map[posx][posy] < map[i][j])
ans[i][j]=max(dfs(posx, posy)+1,ans[i][j]);
}
if (ans[i][j] == -1)
ans[i][j] = 1;
if (ans[i][j] > res)
res = ans[i][j];
return ans[i][j];
}
int main() {
memset(ans, -1, 105*105);
cin >> m >> n;
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
cin >> map[i][j];
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
dfs(i, j);
cout << res;
}
by 快乐一凡 @ 2022-01-26 20:54:15
假设您只有一个点是WA的话,可以下载一下测试数据看看是什么原因。
by 123456xyzMMM @ 2022-02-14 11:38:34
@快乐一凡 怎么下载测试数据啊,我也是只有第二个wa了。