from __future__ import division
weight = [10,20,30]
volume =[60,100,120]
kept = [0,0,0]
M = 50
def knapback(M, weight, volume, kept):
for i in range(0,3):
if weight[i] < M:
kept[i] = 1
M = M-weight[i]
else:
kept[i] = M/weight[i]
knapback(M, weight, volume, kept)
print kept
时间: 2024-10-13 01:03:35