目录
题目描述
给出一批用户,每个用户有 3 种选择 A\B\C,但是价值不同,相临的用户不能选同一个,求
出所有用户选择后总价值最大。
示例
输入:
3
30 8 4
50 20 9
11 7 6
输出:
65
说明:因为选 8 50 7
参考代码
def dfs(idx, com, val):
# idx 用户id,com 三个策略,val 资源消耗
if idx == n - 1:
return val
idx += 1
return max([dfs(idx, c, nums_input[idx][c]) + val for c in [0, 1, 2] if c != com])
def calc():
global n, nums_input
n = int(input())
nums_input = [list(map(int, input().split())) for _ in range(n)]
dp = []
for c in [0, 1, 2]:
dp.append(dfs(0, c, nums_input[0][c]))
print(max(dp))
while True:
try: