开始 2024-08-23 00:00:00

8.19-8.24集训第五天

结束 2024-08-26 08:00:00
Contest is over.
当前 2024-12-22 15:33:33

E题AC题解
#include <iostream>//祖传开头 
using namespace std;
int a[105][105],f[105][105],r,c;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int DFS(int x,int y) 
{
	if (f[x][y] != 0) 
		return f[x][y];
	f[x][y] = 1;
	for(int i = 0;i < 4;i++)
	{
		int nx,ny;
		nx = x + dx[i];
		ny = y + dy[i];
		if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && a[nx][ny] < a[x][y]) \
			f[x][y] = max(f[x][y],DFS(nx,ny) + 1);
	}
	return f[x][y];
}

int main()
{
	int i,j,maxn = -1000000000;
	cin>>r>>c;
	for(i = 1;i <= r;i++) 
	{
		for(j = 1;j <= c;j++)
			 cin>>a[i][j];
	}
	for(i = 1;i <= r;i++) 
	{
		for(j = 1;j <= c;j++) 
			maxn = max(maxn,DFS(i,j));
	}
	cout << maxn;
	return 0;
}

思路:DFS


HAPPY1  •  3个月前

I AK IOI!

火钳刘明


C_Fanhaoyu  •  3个月前

比赛已结束。