Question
Power Company Problem (Recursive/Dynamic) You are hired by a power company to create an application that enables them to efficiently use their employees during a
Power Company Problem (Recursive/Dynamic)
You are hired by a power company to create an application that enables them to efficiently use their employees during a power outage. The town that this power-company provides power for is very rural. The house's power lines depend on each other linearly. This means that if one house loses power all houses after it lose power. For example, on a particular street there maybe 5 houses: A-> B-> C-> D-> E. Each house's power depends on the house preceding it. In other words, house B depends on house A, C depends on B, D depends on C and E depends on D. So if house C has a power problem D and E with being without power but A and B will be fine.
The goal is to figure out what is the least amount of home visits necessary to find where the power problem has occurred. The problem is the houses in the town are very old, so it takes a very long time to diagnose and repair the power in a home. Unfortunately if one of your mechanics visits a house without power they will spend the night attempting to fix the problem even though the problem might not be the house they are visiting. If you had just one mechanic making visits the most efficient way would be to have the mechanic start at house A then go to house B, then continue to house C and so on until they found a house without power and they would know the origin of the problem. But what if you had 2 mechanics what is the least amount of visits necessary to find the problem? The problem is not actually to find the problem, but merely to decide houses from which mechanic should visit so that the total number of visits are minimized.
Given that you have k mechanics and n homes, what is the minimum number of homes you need to visits that is guaranteed to find the home with the power problem?
..A mechanic that visits a house with power can be used again. ..A mechanic the visits a house that does not have working power cannot make any more visits. ..The effect of a visit is the same for all mechanics. ..If a house does not have power, then all houses after it have no power as well. ..If a house has power than all houses before it (the homes it depends on) have power too. ..It is not ruled out that the first house always has power, nor is it ruled out that the last house does not have power.
Example:
Input : mechanics = 2 and houses = 10
Output: 4
The minimum number of visits in the worst case with 2 mechanics and 10 houses is 4.
Use the function public static int minVisits(int mechanics, int houses)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started