Question: Please code in Java. Thanks! You build homes out of wood and you need material from a nearby forest. However, you want to avoid deforestation,

Please code in Java. Thanks! You build homes out of wood andPlease code in Java. Thanks!

You build homes out of wood and you need material from a nearby forest. However, you want to avoid deforestation, so you decide for each tree you cut down, you'll leave its neighbors alone, giving the forest time to recover. However, you still need as much wood as possible, so you have to be careful about which trees you pick to cut down. Write pickTrees, which takes in an array of N trees arr where arx[i] represents how much wood you can harvest by cutting down tree i, It should return the max amount of wood you can harvest while following the rule of skipping neighbors: // Pick tree o, tree 2, and tree 4 => 1 + 3 + 5 = 9 wood total int testresult5 = Ricktrees(new int[] {1, 2, 3, 4, 5}); System.out.println(testResult5); // should output = // Pick tree 1 and tree 3 => 3 + 3 6 wood total int testResult6 = Ricktrees(new int[] {1, 3, 4, 3}); System.outeprintln(testResult); // should output 6 // Pick tree and tree 3 => 5 + 9 = 14 wood total int testResult7 = Ricktrees(new int[] {5, 1, 4, 9}); System.outekrintin(testResult7); // should output 14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!