1 条题解
-
1
#include<queue> #include<math.h> #include<stdio.h> #include<iostream> #include<vector> #include<iomanip> #include<string.h> #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<stack> #include <fstream> #include<string> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int R, C; vector<string> board; int max_count = 0; bool visited[26] = { false }; void dfs( int x , int y, int count) { max_count = max( max_count , count ); int dx[] = { -1 , 1 , 0 , 0 }; int dy[] = { 0 , 0 , -1 , 1 }; for ( int i = 0 ; i < 4 ; i++ ) { int nx = x + dx[i]; int ny = y + dy[i]; if ( nx >= 0 && nx < R && ny >= 0 && ny < C ) { char c = board[nx][ny]; if ( !visited[ c - 'A' ] ) { visited[ c - 'A' ] = true; dfs( nx , ny , count + 1 ); visited[ c - 'A' ] = false; } } } } int main() { cin >> R >> C; board.resize(R); for ( int i = 0 ; i < R ; i++ ) { cin >> board[i]; } visited[ board[0][0] - 'A' ] = true; dfs( 0 , 0 , 1 ); cout << max_count << endl; return 0; }
- 1
信息
- ID
- 1349
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 88
- 已通过
- 24
- 上传者