41.3k views
5 votes
A demolition company has been tasked with taking down n buildings, whose initial heights are positive integers given in an array H[1..n]. The company has two tools at its disposal: - a small explosive, which reduces the height of a single building by 1 , and - a wrecking ball, which reduces the height of all buildings by 1 . The company has an unlimited supply of the small explosives, which are free to use. However, the wrecking ball costs $1000 each time it is used. The company initially has $1000 dollars. They also get $1000 whenever they finish the demolition of a building with the wrecking ball (reducing its height from 1 to 0 ), but they receive no money if the demolition of a building is finished using an explosive. For example, for four buildings of heights [2,3,5,1], the following sequence of actions demolishes all buildings. - Use a small explosive on building 1 , resulting in [1,3,5,1]. - Spend the $1000 to use the wrecking ball, resulting in heights [0,2,4,0]. Buildings 1 and 4 were demolished, so the company receives $2000. - Use the wrecking ball again, leaving heights [0,1,3,0]. No buildings were demolished, so no money is gained. - Use an explosive to demolish building 2 , giving [0,0,3,0]. No money is awarded for completing the demolition of building 2 , since the wrecking ball was not used. - Use explosives three times to demolish building 3. A sequence of actions is minimal if it demolishes all the buildings and there is no shorter sequence of actions that does this. The sequence above is not minimal. Find a minimal sequence of actions to demolish all four buildings in the example above, where the heights are 2, 3, 5 and 1. You must provide reasoning for why your sequence is minimal.

1 Answer

0 votes

Final answer:

To find a minimal sequence of actions to demolish all four buildings with heights 2, 3, 5, and 1, the most efficient approach is to strategically use explosives and the wrecking ball. By doing so, the demolition company can maximize their financial gain.

Step-by-step explanation:

To find a minimal sequence of actions to demolish all four buildings with heights 2, 3, 5, and 1, we need to consider the cost-effectiveness of using the wrecking ball and explosives. By analyzing the problem, we can see that using the wrecking ball is most beneficial when it can demolish multiple buildings at once. Therefore, the minimal sequence is as follows:

  1. Use a small explosive on building 1, resulting in heights [1, 3, 5, 1].
  2. Spend 1000 to use the wrecking ball, resulting in heights [0, 2, 4, 0]. Buildings 1 and 4 were demolished, so the company receives 2000.
  3. Use the wrecking ball again, leaving heights [0, 1, 3, 0]. No buildings were demolished, so no money is gained.
  4. Use an explosive to demolish building 2, giving [0, 0, 3, 0]. No money is awarded for completing the demolition of building 2, since the wrecking ball was not used.
  5. Use explosives three times to demolish building 3.

This sequence is minimal because it efficiently uses the wrecking ball to demolish multiple buildings at once, maximizing the financial gain.

User MrFiveT
by
8.3k points