33 lines
1.5 KiB
Text
33 lines
1.5 KiB
Text
T Bounty
|
||
Int value
|
||
Float weight, volume
|
||
F (value, weight, volume)
|
||
(.value, .weight, .volume) = (value, weight, volume)
|
||
|
||
V panacea = Bounty(3000, 0.3, 0.025)
|
||
V ichor = Bounty(1800, 0.2, 0.015)
|
||
V gold = Bounty(2500, 2.0, 0.002)
|
||
V sack = Bounty( 0, 25.0, 0.25)
|
||
V best = Bounty( 0, 0, 0)
|
||
V current = Bounty( 0, 0, 0)
|
||
|
||
V best_amounts = (0, 0, 0)
|
||
|
||
V max_panacea = Int(min(sack.weight I/ panacea.weight, sack.volume I/ panacea.volume))
|
||
V max_ichor = Int(min(sack.weight I/ ichor.weight, sack.volume I/ ichor.volume))
|
||
V max_gold = Int(min(sack.weight I/ gold.weight, sack.volume I/ gold.volume))
|
||
|
||
L(npanacea) 0 .< max_panacea
|
||
L(nichor) 0 .< max_ichor
|
||
L(ngold) 0 .< max_gold
|
||
current.value = npanacea * panacea.value + nichor * ichor.value + ngold * gold.value
|
||
current.weight = npanacea * panacea.weight + nichor * ichor.weight + ngold * gold.weight
|
||
current.volume = npanacea * panacea.volume + nichor * ichor.volume + ngold * gold.volume
|
||
|
||
I current.value > best.value & current.weight <= sack.weight & current.volume <= sack.volume
|
||
best = current
|
||
best_amounts = (npanacea, nichor, ngold)
|
||
|
||
print(‘Maximum value achievable is ’best.value)
|
||
print(‘This is achieved by carrying (one solution) #. panacea, #. ichor and #. gold’.format(best_amounts[0], best_amounts[1], best_amounts[2]))
|
||
print(‘The weight to carry is #2.1 and the volume used is #.3’.format(best.weight, best.volume))
|