同45,不知道错哪儿了 public static void main(String[] args) { Scanner sc = new Scanner(System.in); String nn = sc.nextLine(); int n = Integer.valueOf(nn); String a1 = sc.nextLine(); String a2 = sc.nextLine(); char[][] arr = new char[3][n+1]; for (int i = 1; i <= n; i++) { arr[1][i] = a1.charAt(i - 1); } for (int i = 1; i <= n; i++) { arr[2][i] = a2.charAt(i - 1); } int[][] dp = new int[3][n + 1]; dp[1][1] = 1; dp[2][1] = 0; for (int i = 2; i <= n; i++) { if (arr[1][i] == &#39;X&#39;) { dp[1][i] = 0; } else { dp[1][i] = dp[1][i - 1] + dp[2][i - 1]; } if (arr[2][i] == &#39;X&#39;) { dp[2][i] = 0; } else { dp[2][i] = dp[2][i - 1] + dp[1][i - 1]; } } System.out.println(dp[2][n] == 0 ? -1 : dp[2][n]); }
点赞 评论

相关推荐

牛客网
牛客企业服务