Knapsack problem/0-1: Difference between revisions

m
Line 3,080:
_weightOfKnapsack = 400
 
dim as short n : n = _numberOfObjects /* The number of objects available to pack */
dim as Str31 s(_numberOfObjects) /* The names of available objects */
dim as short c(_numberOfObjects) /* The *COST* of the ith object i.e. how much weight you must carry to pack the object */
dim as short v(_numberOfObjects) /* The *VALUE* of the ith object i.e. on a scale of 1 to 200, how important is it that the object included */
dim as short W : W = _weightOfKnapsack /* The maximum weight your knapsack will carry in ounces*/
 
s(0) = "map"
Line 3,157:
 
local fn FillKnapsack
dim as short cur_w
dim as double tot_v : tot_v = 0
dim as short i, maxi, finalWeight : finalWeight = 0
dim as short finalValue : finalValue = 0
dim as short used(_numberOfObjects)
for i = 0 to n
Line 3,203:
end fn
 
dim as short i, totalValue, totalWeight
 
print
Line 3,226:
 
HandleEvents</lang>
{{output}}
 
Output:
<pre>
 
717

edits