+ 1

# If It is possible then show me...It's a challange

11 Items are in a shop and every item has a different price and weight. a thief is going to stolen items but it has capacity of 79 units of weight to carry. now he has to carry more expensive items in 79 units. how can we make an algorithm for that problem? weight & price 6 6 28 28 41 40 32 31 38 36 10 9 29 26 26 23 66 57 21 18 2 1

5 Réponses

+ 2

Sort based on a ratio of price to weight.
ie.
return (a.price/a.weight>b.price/b.weight?a:b);
or something functionally equivalent.

+ 2

the answer I gave you should have solved this other than that are you just looking for someone to write the algorithm for you?

+ 1

Steps :
1) Sort the list of weights and prices according to the criteria (keep more expensive and less weighing items on top).
2) Add the items from the top to the thief's bag till 79 weight units are reached.
Can you provide a sample answer to compare? Maybe for the case you posted?

0

thief wants the precise answer which is the best one know think, and reply me an structure of it, this is a sample of problem, actual problem is bigger than it, one more thing if we set loop it will run a 2^11 iterations, which will take a huge time..., so make an algorithm to solve the problem. you can also email me @
naeem1098@gmail.com

0

no thanx Michael.