Greedy Algorithoms---knapback

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

posted @ 2016-06-07 08:36  zhaodonglin  Views(133)  Comments(0)    收藏  举报