编辑代码

def optimize_tour(total_days, duration, scores):
    n = len(duration)
    dp = [0] * (total_days + 1)

    for i in range(n):
        for j in range(total_days, 0, -1):
            if j >= duration[i]:
                dp[j] = max(dp[j], dp[j - duration[i]] + scores[i])

    return dp[total_days]

# 景点数据
attractions = ["故宫", "颐和园", "长城", "天坛"]
duration = [1, 2, 3, 1]
scores = [7, 8, 9, 6]

# 总时间限制
total_days = 4

# 计算最大价值
max_score = optimize_tour(total_days, duration, scores)

print("最大价值:", max_score)