8 条题解
-
0
DFS
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1e3 + 5; const int INF = 0x3f3f3f3f; char g[N][N]; int vis[N][N]; int n, m ,ans; int dx[] = {0,0,-1,1}; int dy[] = {1,-1,0,0}; string s = "tencent"; void dfs(int x,int y,int c) { if(x < 1 || x > n || y < 1 || y > m) return; if(g[x][y] != s[c]) return; if(c == 6 && g[x][y] == s[6]) { ans++; return; } for(int i = 0;i < 4;i++){ int x1 = x + dx[i];int y1 = y + dy[i]; if(vis[x1][y1]) continue; vis[x1][y1] = 1; dfs(x1,y1,c + 1); vis[x1][y1] = 0; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) cin >> g[i][j]; for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ if(g[i][j] == 't') dfs(i,j,0); } } cout << ans << endl; return 0; }
信息
- ID
- 81
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 302
- 已通过
- 83
- 上传者