提交时间:2024-06-09 14:09:03
运行 ID: 48567
def buy_chickens(x, y, z, n, m): dp = [[[0] * (m + 1) for _ in range(m + 1)] for _ in range(n + 1)] dp[0][0][0] = 1 for i in range(n + 1): for j in range(m + 1): for k in range(m + 1): if i - x >= 0 and j > 0: dp[i][j][k] += dp[i - x][j - 1][k] if i - y >= 0 and k > 0: dp[i][j][k] += dp[i - y][j][k - 1] if i - z >= 0: dp[i][j][k] += dp[i - z][j][k] count = 0 for j in range(m + 1): for k in range(m + 1): if j + k == m: count += dp[n][j][k] return count # 示例 x, y, z, n, m = 5, 3, 3, 100, 100 print(buy_chickens(x, y, z, n, m)) # 输出 4