AcWing 734. 能量石python
原题链接
困难
作者:
小沈____
,
2020-09-02 09:04:36
,
所有人可见
,
阅读 474
能量石python
n = int(input())
r = []
while n:
m = int(input())
nums = []
t = 0
#: 预先处理数组 排序
for _ in range(m):
list_n = list(map(int,input().split()))
nums.append(list_n)
t += list_n[0]
nums.sort(key = lambda x:x[2]/x[0],reverse = True)
data = [float('-inf')]*(t+1)
data[0] = 0
len_n = len(nums)
res = 0
#:0 1 背包问题
for i in range(len_n):
s,e,l = nums[i][0],nums[i][1],nums[i][2]
for j in range(t,-1,-1):
if j >= nums[i][0]:
data[j] = max(data[j],data[j-s]+max(0,e-(j-s)*l))
r.append(max(data))
n -= 1
for i in range(len(r)):
print("Case #{}: {}".format(i+1,r[i]))