- LETTERS
有趣的问题
- @ 2025-11-18 14:59:59
这是我的ac代码:
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
int dx[] = {0,0,-1,1,1,1,-1,-1};
int dy[] = {1,-1,0,0,1,1,-1,-1};
int R,S,ans,cnt=1;
char map[25][25];
bool vis[25][25];
bool mp[100010];
void dfs(int x,int y){
/*if(x >= S || x < 1 || y >= R || y < 1 || vis[x][y] == 1 || alphabeticalVis[map[x][y] - 'A'] == 1){
return;
}*/
//alphabeticalVis[map[x][y] - 'A'] = true;
for(int i = 0;i < 4;i++){
int nx = x + dx[i],ny = y + dy[i];
if(mp[map[nx][ny]] == true || nx < 1 || ny < 1 || nx > R || ny > S || vis[nx][ny] == 1)
continue;//越界处理.
mp[map[nx][ny]] = 1;
cnt++;
vis[nx][ny] = 1;
dfs(nx,ny);
mp[map[nx][ny]] = 0;
vis[nx][ny] = 0;
cnt--;
}ans = max(ans,cnt);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> R >> S;
for(int i = 1;i <= R;i++){
for(int j = 1;j <= S;j++){
cin >> map[i][j];
}
}
vis[1][1] = 1;
mp[(int)map[1][1]] = 1;
dfs(1,1);
cout << ans;
return 0;
//cout << __cplusplus;
}
众所周知,第10行的mp[]数组是记录地图中的已走过字母的,
然后我发现mp[]的数组大小可以乱改,也不会影响到程序的运行。In other word,乱改mp数组大小也可以AC(???)
Example: mp[1] ; mp['A'+26]
这是真的!!! 不行你自己试
0 comments
No comments so far...
Information
- ID
- 698
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 299
- Accepted
- 40
- Uploaded By