⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 滑雪.txt.txt

📁 滑雪游戏实现代码
💻 TXT
字号:

#include <stdio.h>
#include <string.h>

#define MAXN 100

const int dx[4] = { -1, 0, 0, 1 };
const int dy[4] = { 0, -1, 1, 0 };

int m, n, maxh;
int h[MAXN][MAXN], max[MAXN][MAXN];

bool init()
{
	if( scanf( "%d %d", &m, &n ) == EOF )
		return false;

	for( int i = 0; i < m; ++i )
		for( int j = 0; j < n; ++j )
			scanf( "%d", &h[i][j] );

	memset( max, -1, sizeof( max ) );
	maxh = 0;

	return true;
}

int search_it( int x, int y )
{
	if( max[x][y] != -1 )
		return max[x][y];

	max[x][y] = 1;
	for( int i = 0; i < 4; ++i )
	{
		int xx = x + dx[i], yy = y + dy[i];
		if( xx >= 0 && xx < m 
			&& yy >=0 && yy < m && h[xx][yy] < h[x][y] )
		{
			int nowmax = search_it( xx, yy );
			if( nowmax + 1 > max[x][y] )
				max[x][y] = nowmax + 1;
		}
	}
	if( max[x][y] > maxh )
		maxh = max[x][y];

	return max[x][y];
}

int main()
{
	while( init() )
	{
		for( int i = 0; i < m; ++i )
			for( int j = 0; j < n; ++j )
				search_it( i, j );
		printf( "%d\n", maxh );
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -