RosettaCodeData/Task/Knapsack-problem-Unbounded/00DESCRIPTION

77 lines
3.5 KiB
Plaintext

A traveler gets diverted and has to make an unscheduled stop in what turns out to be Shangri La.   Opting to leave, he is allowed to take as much as he likes of the following items, so long as it will fit in his knapsack, and he can carry it.
He knows that he can carry no more than   25   'weights' in total;   and that the capacity of his knapsack is   0.25   'cubic lengths'.
Looking just above the bar codes on the items he finds their weights and volumes.   He digs out his recent copy of a financial paper and gets the value of each item.
<table
style="text-align: left; width: 80%;" border="4"
cellpadding="2" cellspacing="2"><tr><td
style="font-weight: bold;" align="left" nowrap="nowrap"
valign="middle">Item</td><td
style="font-weight: bold;" align="left" nowrap="nowrap"
valign="middle">Explanation</td><td
style="font-weight: bold;" align="left" nowrap="nowrap"
valign="middle">Value (each)</td><td
style="font-weight: bold;" align="left" nowrap="nowrap"
valign="middle">weight</td><td
style="font-weight: bold;" align="left" nowrap="nowrap"
valign="middle">Volume (each)</td></tr><tr><td
align="left" nowrap="nowrap" valign="middle">panacea
(vials of)</td><td align="left" nowrap="nowrap"
valign="middle">Incredible healing properties</td><td
align="left" nowrap="nowrap" valign="middle">3000</td><td
align="left" nowrap="nowrap" valign="middle">0.3</td><td
align="left" nowrap="nowrap" valign="middle">0.025</td></tr><tr><td
align="left" nowrap="nowrap" valign="middle">ichor
(ampules of)</td><td align="left" nowrap="nowrap"
valign="middle">Vampires blood</td><td align="left"
nowrap="nowrap" valign="middle">1800</td><td
align="left" nowrap="nowrap" valign="middle">0.2</td><td
align="left" nowrap="nowrap" valign="middle">0.015</td></tr><tr><td
align="left" nowrap="nowrap" valign="middle">gold
(bars)</td><td align="left" nowrap="nowrap"
valign="middle">Shiney shiney</td><td align="left"
nowrap="nowrap" valign="middle">2500</td><td
align="left" nowrap="nowrap" valign="middle">2.0</td><td
align="left" nowrap="nowrap" valign="middle">0.002</td></tr><tr><td
style="background-color: rgb(255, 204, 255);" align="left"
nowrap="nowrap" valign="middle">Knapsack</td><td
style="background-color: rgb(255, 204, 255);" align="left"
nowrap="nowrap" valign="middle">For the carrying of</td><td
style="background-color: rgb(255, 204, 255);" align="left"
nowrap="nowrap" valign="middle">-</td><td
style="background-color: rgb(255, 204, 255);" align="left"
nowrap="nowrap" valign="middle">&lt;=25</td><td
style="background-color: rgb(255, 204, 255);" align="left"
nowrap="nowrap" valign="middle">&lt;=0.25&nbsp;</td></tr>
</table>
<br>
He can only take whole units of any item, but there is much more of any item than he could ever carry
;Task:
Show how many of each item does he take to maximize the value of items he is carrying away with him.
;Note:
* &nbsp; There are four solutions that maximize the value taken. &nbsp; Only one ''need'' be given.
<!-- All solutions
# ((value, -weight, -volume), (#panacea, #ichor, #gold)
[((54500, -25.0, -0.24699999999999997), (0, 15, 11)),
((54500, -24.899999999999999, -0.247), (3, 10, 11)),
((54500, -24.800000000000001, -0.24700000000000003), (6, 5, 11)),
((54500, -24.699999999999999, -0.247), (9, 0, 11))]
# (9, 0, 11) also minimizes weight and volume within the limits of calculation
-->
;Related tasks:
* &nbsp; [[Knapsack problem/Bounded]]
* &nbsp; [[Knapsack problem/Continuous]]
* &nbsp; [[Knapsack problem/0-1]]
<br><br>