站外题求助
  • 板块学术版
  • 楼主_Glassy_Sky_
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/5/21 10:28
  • 上次更新2023/10/23 15:09:46
查看原帖
站外题求助
677581
_Glassy_Sky_楼主2023/5/21 10:28

http://ybt.ssoier.cn:8088/problem_show.php?pid=1212

代码:

#include<bits/stdc++.h>
using namespace std;
int fx[4] = {0, 1, 0, -1};
int fy[4] = {-1, 0, 1, 0};
int R, S, ans;
char a[200][200];
bool f[50000];
int dfs(int x, int y, int z)
{
	ans = max(ans, z);
	for(int i = 0; i < 4; i ++)
	{
		int xx = x + fx[i];
		int yy = y + fy[i];
		if(xx <= R && xx > 0 && yy <= S && yy > 0 && !f[a[xx][yy]])
		{
			f[a[xx][yy]] = true;
			dfs(xx, yy, z + 1);
			f[a[xx][yy]] = false;
		}
	}
}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> R >> S;
	for(int i = 1; i <= R; i ++)
		for(int j = 1; j <= S; j ++)
			cin >> a[i][j];
	f[a[1][1]] = true;
	dfs(1, 1, 1);
	cout << ans;
	return 0;
}


2023/5/21 10:28
加载中...