顺丰笔试 赏金

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%,求大佬帮看看。

另外第一道服务器的不会做。。求指点
#顺丰科技##笔试题目#
全部评论
第16行改成小于就100了
1 回复
分享
发布于 2020-08-20 21:55
https://www.nowcoder.com/discuss/483790?toCommentId=6905554 有我的答案
点赞 回复
分享
发布于 2020-08-20 21:57
博乐游戏
校招火热招聘中
官网直投
以结束时间排序 请问怎么比较呢
点赞 回复
分享
发布于 2020-08-20 22:02
服务器贪心就行,优先给钱多的分配
点赞 回复
分享
发布于 2020-08-20 22:03

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务