求助:第二个点为什么WA啊
查看原帖
求助:第二个点为什么WA啊
433642
m泛函625楼主2022/1/26 20:49

求助大佬们第二个点

#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;
}
2022/1/26 20:49
加载中...