I need an algorithm for the following problem:
There's a tree with N fruits each with its own weight w and height h. I can only reach a fruit if it's no taller than H inches. Also every time I pick a fruit, all the other fruits in the tree rise by exactly U inches. I need to find out the maximum amount (total weight) of fruits I can collect.
Slobodino
0
Newbie Poster
Recommended Answers
Jump to PostYou haven't given enough information to solve the problem, yet.
Jump to PostHave you tried to do anything yet, I'd like to help but I won't do you program from start to finish. It looks like it could be solved using a 0-1 knapsack with slight modification for the heights changing as you pick. If you post some code you're working/stuck on …
Jump to Postwithout any example input and expected output I'm not 100% positive that this will work but I'm almost positive that this should do the trick.
Notice I changed j which iterates through possible heights to start at 0. Yours starting at 1 is fine as long as you are guaranteed …
All 9 Replies
Adak
419
Nearly a Posting Virtuoso
craig_ka
0
Newbie Poster
Slobodino
0
Newbie Poster
craig_ka
0
Newbie Poster
nezachem
616
Practically a Posting Shark
abhimanipal
91
Master Poster
Slobodino
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
craig_ka
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.