害,我第一题用dp ac了45%,第二题暴力36%,明明感觉很简单,我死活找不到错误。一气之下直接交卷了。 又没有大佬帮我看看我的第一题代码到底啥问题 def calWagsNums(n, row1, row2): grids = [row1, row2] if grids[0][0] == "X": return -1 dp = [[0 for _ in range(n)] for _ in range(2)] dp[0][0], dp[1][0] = 1, 0 grids[0][0] = 1 for j in range(1, n): for i in range(2): if grids[i][j] == "X": continue dp[i][j] = 0 if j - 1 >= 0: dp[i][j] += dp[i][j - 1] if i - 1 >= 0: dp[i][j] += dp[i - 1][j - 1] if i + 1 < 2: dp[i][j] += dp[i + 1][j - 1] return dp[-1][-1] if dp[-1][-1] != 0 else -1