[AC]python解
查看原帖
[AC]python解
934466
KKKvX07楼主2024/6/15 10:16
def horse_controlled(x, y, hx, hy):
    horse_moves = [(2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)]
    controlled_points = [(hx, hy)] + [(hx + dx, hy + dy) for dx, dy in horse_moves]
    return (x, y) in controlled_points

def count_paths(n, m, hx, hy):
    dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
    dp[0][0] = 1

    for x in range(n + 1):
        for y in range(m + 1):
            if x == 0 and y == 0:
                continue
            if horse_controlled(x, y, hx, hy):
                dp[x][y] = 0
            else:
                dp[x][y] = (dp[x - 1][y] if x > 0 else 0) + (dp[x][y - 1] if y > 0 else 0)

    return dp[n][m]

# 输入
n, m, hx, hy = map(int, input().split())
# 计算并输出结果
print(count_paths(n, m, hx, hy))
2024/6/15 10:16
加载中...