n = 3 tasks = [ [5, 10, 1], [2, 7, 3], [1, 3, 5], ] if n == 0: print(0) tasks = sorted(tasks, key=lambda x: x[1]) dp = [0] * n dp[0] = tasks[0][2] for i in range(1, len(tasks)): choice1 = dp[i-1] choice2 = tasks[i][2] for j in range(i-1, -1, -1): if tasks[j][1] <= tasks[i][0]: choice2 += dp[j] break dp[i] = max(choice1, choice2) print(dp[n-1])
通过了91%,求大佬帮看看。
另外第一道服务器的不会做。。求指点
全部评论
(4) 回帖