U11Try4
This commit is contained in:
parent
39318b5acb
commit
436a92c84a
@ -18,8 +18,26 @@ def maximum_value(maximum_weight, items):
|
||||
weight.append(curent_dic.get("weight"))
|
||||
value.append(curent_dic.get("value"))
|
||||
i +=1
|
||||
#batoh_s_pamatou(kapacita, hodnoty, hmotnosti): z prednasky
|
||||
pamat = {}
|
||||
def vyries(pocet,zostava):
|
||||
if pocet == 0 or zostava == 0:
|
||||
return 0
|
||||
stav = (pocet,zostava)
|
||||
if stav in pamat:
|
||||
return pamat[stav]
|
||||
|
||||
index = pocet - 1
|
||||
better = vyries(pocet - 1,zostava)
|
||||
|
||||
if weight[index] <=zostava:
|
||||
better = max(better,value[index] + vyries(pocet - 1,zostava - weight[index]))
|
||||
pamat[stav] = better
|
||||
return better
|
||||
|
||||
return vyries(len(weight),maximum_weight)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def maximum_value_with_items(maximum_weight, items):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user