N=105
#f[i][j] 表示从前i件物品中选,体积<=j,属性为价值max
#分割点:不选取第i件物品 f[i-1][j]
#选取第i件物品k件 f[i-1][j-k*v[i]]+w[i]*k
f=[[0 for i in range(N)]for j in range(N)]
v=[0 for i in range(N)]
w=[0 for i in range(N)]
s=[0 for i in range(N)]
n,v1=map(int,input().split())
for i in range(1,n+1):
v[i],w[i],s[i]=map(int,input().split())
for i in range(1,n+1):
for j in range(v1+1):
f[i][j]=f[i-1][j]
for k in range(s[i]+1):
if k*v[i]<=j:
f[i][j]=max(f[i][j],f[i-1][j-v[i]*k]+w[i]*k)
print(f[n][v1])
多重背包问题 I
于 2022-03-22 09:06:21 首次发布