1 条题解
-
0117爱好者 (mengqingyu) LV 10 @ 2024-7-29 14:19:31
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define PII pair<int, int> const LL N = 200 + 10; const LL INF = 0x3f3f3f3f; const int P = 131; const ULL MOD = ULONG_LONG_MAX; int n, ans; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; bool vis[N][N]; char s[N][N]; bool flag(int x, int y) { return (x > n || y > n || x < 1 || y < 1 || vis[x][y] || s[x][y] == 'X'); } void dfs(int x, int y, int sum) { if(s[x][y] == '$') { ++sum; ans = max(ans, sum); } for(int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if(!flag(nx,ny)) vis[nx][ny] = 1, dfs(nx, ny, sum); } } signed main() { // IO; cin >> n; for(int i = 1; i <= n; i++) scanf("%s", s[i]+1); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(!vis[i][j] && s[i][j] != 'X') dfs(i, j, 0); } } cout << ans << endl; return 0; }
- 1
信息
- ID
- 2949
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 596
- 已通过
- 31
- 上传者