View Code of Problem 17

#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int a[100][100];
int maxx = 0;
void walk(int x, int y, int pos)
{
	if (a[x][y] < a[x + 1][y]) walk(x + 1, y, pos + 1);
	if (a[x][y] < a[x][y + 1]) walk(x, y + 1, pos + 1);
	if (a[x][y] < a[x - 1][y]) walk(x - 1, y, pos + 1);
	if (a[x][y] < a[x][y - 1]) walk(x, y - 1, pos + 1);
	if (pos > maxx)
		maxx = pos;
	return;
}
int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m) != EOF)
	{
		maxx=0;
		for (int i = 0;i < n;i++)
		{
			for (int j = 0;j < m;j++)
			{
				scanf("%d", &a[i][j]);
			}
		}
		for (int i = 0;i < n;i++)
		{
			for (int j = 0;j < m;j++)
			{
				walk(i, j, 0);
			}
		}
		printf("%d\n", maxx);
	}
	
}

Double click to view unformatted code.


Back to problem 17