POJ-1088~~~~~滑雪(递归+记忆化搜索)

#include
#include
#include
using namespace std;
int maps[105][105];
int dis[105][105] = {0};
int R, C;
int dfs(int x, int y)
{
	if (dis[x][y] > 0) return dis[x][y];
	int up = 1, down = 1, left = 1, right = 1;
	if (y+1 < C && maps[x][y] > maps[x][y+1]) up = 1 + dfs(x,y+1);
	if (y-1 >= 0 && maps[x][y] > maps[x][y-1]) down = 1 + dfs(x,y-1);
	if (x+1 < R && maps[x][y] > maps[x+1][y]) right = 1 + dfs(x+1,y);
	if (x-1 >= 0 && maps[x][y] > maps[x-1][y]) left = 1 + dfs(x-1,y);
	if (down > up) up = down;
	if (left > up) up = left;
	if (right > up) up = right;
	return up;
}
int main()
{
	int MAX = -1;
	cin >> R >> C;
	for (int i = 0; i < R; i++)
		for (int j = 0; j < C; j++)
			 cin >> maps[i][j];
	for (int i = 0; i < R; i++)
		for (int j = 0; j < C; j++)
		{
			dis[i][j] = dfs(i,j); 
			if (dis[i][j] > MAX) MAX = dis[i][j];
		}
	cout << MAX << endl;
	system("PAUSE");
	return 0;
}

你可能感兴趣的:(POJ-1088~~~~~滑雪(递归+记忆化搜索))