Click here to Skip to main content
15,891,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Question:
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it and it will have to last the whole day. He creates a list of what he wants to bring for the trip but the total weight of all items is too much. He then decides to add columns to his initial list detailing their weights and a numerical value representing how important the item is for the trip.

The tourist can choose to take any combination of items from the list, but only one of each item is available. He may not cut or diminish the items, so he can only take whole units of any item.
Which items does the tourist choose in order to get the total maximum value and not exceed the weight that the knapsack can carry?

Here is the list:
item 	weight (grams) 	value 
map 	         90 	150 
compass 	 130 	35 
water 	        1530 	300 
Gold bar 	3000 	130 
sandwich 	500 	160 
glucose 	150 	60 
tin 	        680 	45 
banana   	270 	60 
apple 	        390 	40 
cheese   	230 	30 
beer 	        620 	10 
suntan cream 	110 	70 
camera          320 	30 
T-shirt 	240 	15 
trousers 	480 	10
Posted
Updated 2-Oct-14 8:51am
v2
Comments
BillWoodruff 2-Oct-14 14:38pm    
How many beers can the tourist drink while deciding what to pack ?
PIEBALDconsult 2-Oct-14 14:47pm    
We don't do homework.
ZurdoDev 2-Oct-14 14:48pm    
You'll fail your class then. I always did my homework. Hated it, but did it.
PIEBALDconsult 2-Oct-14 14:52pm    
There's a little something brown on your nose...
ZurdoDev 2-Oct-14 14:54pm    
Not at all. For me it would have taken more effort to get Fs than As. :)

Please do not post SPAM here. If you have an actual question please let us know otherwise just use Excel to do this.
 
Share this answer
 
Comments
kolisa 2-Oct-14 14:30pm    
its no Spam
ZurdoDev 2-Oct-14 14:33pm    
OK. Do you have a specific question then? We would love to help but there is no question here.
kolisa 2-Oct-14 14:45pm    
I am not sure if you see the table below, basically i want to create c# application using patterns and check if the user that has already selected item if yes then the user can select if but the total weight of selected items must be 4kg not more than that
ZurdoDev 2-Oct-14 14:48pm    
Yes, I understand that is what you want. But let's say, for example, that it will take 3000 lines of code to do what you want. We're not going to give you all that code. So, where are you stuck? Give us something specific to help you with.
kolisa 2-Oct-14 14:46pm    
i was trying to attach an excel table but am unable, if you have any examples that might help me to solve this problem i would highly appreciate
Why not try it with actual objects and write down the steps you folllow?
 
Share this answer
 
Comments
BillWoodruff 3-Oct-14 14:29pm    
+5 imho, this reeks of Solomonic wisdom !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900