深度优先遍历: def dfs(pb, i, j, n, res): if j == n-1: if i == 1: res[0] += 1 return for ne in get_neigh(i, j, n): if pb[ne[0]][ne[1]]: pb[ne[0]][ne[1]] == False dfs(pb, ne[0], ne[1], n, res) pb[ne[0]][ne[1]] == True def get_neigh(i, j, x): neigh = [] if j+1 < x: neigh.append([i, j+1]) if j+1 < x and i == 0: neigh.append([i+1, j+1]) if j+1 < x and i == 1: neigh.append([i-1, j+1]) return neigh if __name__ == &#39;__main__&#39;: n = int(input()) p = [] p.append(list(input())) p.append(list(input())) pb = [[True for i in range(n)] for i in range(2)] for i in range(2): for j in range(n): if p[i][j] != &#39;.&#39;: pb[i][j] = False pb[0][0] = False res = [0] dfs(pb, 0, 0, n, res) res = res[0] if res[0] > 0 else -1 print(res)
点赞 评论

相关推荐

10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
11-13 20:32
门头沟学院 Java
面向未来编程code:我没看到他咋急,他不就问你个问题。。。
点赞 评论 收藏
分享
牛客网
牛客企业服务