深圳住房和建设局网站办事跟踪,苏州软件开发公司哪家好,科技展厅,搜索引擎排名优化建议题意#xff1a;有横向和纵向的街道#xff0c;每个街道只有一个方向#xff0c;垂直的街道相交会产生一个节点#xff0c;这样每个节点都有两个方向#xff0c; 问是否每一个节点都可以由其他的节点到达.... 思路#xff1a;规律没有想到#xff0c;直接爆搜#xff0… 题意有横向和纵向的街道每个街道只有一个方向垂直的街道相交会产生一个节点这样每个节点都有两个方向 问是否每一个节点都可以由其他的节点到达.... 思路规律没有想到直接爆搜每一个节点dfs一次记录每个节节点被访问的次数如果每个节点最终的访问次数 和所有节点的数目相同则输出“YES, 否则输出”NO“ 1 #include queue2 #include string3 #include cstdio4 #include cstring5 #include iostream6 #include algorithm7 8 using namespace std;9
10 char s1[25], s2[25];
11 int vis[25][25];
12 int cnt[25][25];
13 int n, m;
14
15 void dfs(int x, int y){
16 if(x1 || xn || y1 || ym || vis[x][y]) return;
17 cnt[x][y];
18 vis[x][y] 1;
19 if(s1[x] )
20 dfs(x, y-1);
21 else dfs(x, y1);
22
23 if(s2[y] v)
24 dfs(x1, y);
25 else dfs(x-1, y);
26 }
27
28 int main(void)
29 {
30 scanf(%d%d, n, m);
31 scanf(%s%s, s11, s21);
32
33 for(int i1; in; i)
34 for(int j1; jm; j){
35 memset(vis, 0, sizeof(vis));
36 dfs(i, j);
37 }
38 int s n*m;
39 for(int i 1; in; i)
40 for(int j1; jm; j)
41 if(cnt[i][j] ! s){
42 coutNOendl;
43 return 0;
44 }
45 coutYESendl;
46 return 0;
47 } View Code 转载于:https://www.cnblogs.com/hujunzheng/p/4007917.html