题解 | #购物单#

购物单

http://www.nowcoder.com/practice/f9c6f980eeec43ef85be20755ddbeaf4

抄作业真相,leetcode太卷了,还是牛客刷题有感觉

money,capacity = map(int ,input().split(" "))
money //=10
weight = [[0]*3 for _ in range(capacity+1)]
satisfaction = [[0]*3 for _ in range(capacity+1) ]
answer = [[0]*(money+1) for _ in range(capacity+1)]
for i in range(1,capacity+1):
    price,importance,primary = map(int,input().split())
    price //= 10
    if primary==0:
        weight[i][0]=price
        satisfaction[i][0]=price*importance
    elif weight[primary][1]==0:
        weight[primary][1]=price
        satisfaction[primary][1]=price*importance
    else:
        weight[primary][2]=price
        satisfaction[primary][2]=price * importance
        
for i in range(1,capacity+1):
    for j in range(0,money+1):
        if j >= weight[i][0]:
            answer[i][j]=max(answer[i-1][j],answer[i-1][j-weight[i][0]]+satisfaction[i][0])
            if j >= weight[i][0]+weight[i][1]:
                answer[i][j]=max(answer[i][j],answer[i-1][j-weight[i][0]-weight[i][1]]+satisfaction[i][0]+satisfaction[i][1])
            if j >= weight[i][0]+weight[i][2]:
                answer[i][j]=max(answer[i][j],answer[i-1][j-weight[i][0]-weight[i][2]]+satisfaction[i][0]+satisfaction[i][2])
                if j >= weight[i][0]+weight[i][2]+weight[i][1]:
                    answer[i][j]=max(answer[i][j],answer[i-1][j-weight[i][0]-weight[i][2]-weight[i][1]]+satisfaction[i][0]+satisfaction[i][2]+satisfaction[i][1])
        else:
            answer[i][j] = answer[i-1][j]
print(answer[capacity][money]*10)
                
                
                
                
                
                
                
                
                
                
                
            
全部评论
抄作业真香,leetcode太卷了,还是牛客刷题有感觉
点赞 回复 分享
发布于 2022-06-25 14:40

相关推荐

评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务