动态规划: if __name__ == '__main__': n = int(input()) p = [] p.append(list(input())) p.append(list(input())) dp = [[0 for i in range(n)] for i in range(2)] 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] != '.': pb[i][j] = False dp[-1][-2] = 1 if pb[-1][-2] else 0 dp[-2][-2] = 1 if pb[-2][-2] else 0 for j in range(-3, -n-1, -1): for i in range(-1, -3, -1): if pb[i][j]: if i == -1: dp[i][j] = dp[i-1][j+1] + dp[i][j+1] if i == -2: dp[i][j] = dp[i][j+1] + dp[i+1][j+1] res = dp[0][0] if dp[0][0] > 0 else -1 print(res)