answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mariana [72]
2 years ago
9

Assume that you have a list of n home maintenance/repair tasks (numbered from 1 to n ) that must be done in numeric order on you

r house. You can either do each task i yourself at a positive cost (that includes your time and effort) of c[i] . Alternatively, you could hire a handyman who will do the next 4 tasks for the fixed cost h (regardless of how much time and effort those 4 tasks would cost you). The handyman always does 4 tasks and cannot be used if fewer than four tasks remain. Create a dynamic programming algorithm that finds a minimum cost way of completing the tasks. The inputs to the problem are h and the array of costs c[1],...,c[n] .
a) Find and justify a recurrence (without boundary conditions) giving the optimal cost for completing the tasks. Use M(j) for the minimum cost required to do the first j tasks.

b) Give an O(n) -time recursive algorithm with memoization for calculating the M(j) values.

c) Give an O(n) -time bottom-up algorithm for filling in the array.

d) Describe how to determine which tasks to do yourself, and which tasks to hire the handyman for in an optimal solution.
Computers and Technology
1 answer:
tangare [24]2 years ago
4 0

Answer:

Explanation:

(a) The recurrence relation for the given problem is :

T(n) = T(n-1) + T(n-4) + 1

(b) The O(n) time recursive algorithm with memoization for the above recurrence is given below :

Create a 1-d array 'memo' of size, n (1-based indexing) and initialize its elements with -1.

func : a recursive function that accepts the cost array and startingJobNo and returns the minimum cost for doing the jobs from startingJobNo to n.

Algorithm :

func(costArr[], startingJobNo){

if(startingJobNo>n)

then return 0

END if

if(memo[startingJobNo] != -1)

then return memo[startingJobNo];

END if

int ans1 = func(costArr, startingJobNo+1) + costArr[startingJobNo]

int ans2 = func(costArr, startingJobNo+4) + h

memo[startingJobNo] = min(ans1,ans2);

return memo[startingJobNo];

}

(c)

First, Create a 1-d array 'dp' of size, N+1.

dp[0] = 0

bottomUp(int c[]){

for  i=1 till i = n

DO

dp[i] = min(dp[i-1] + c[i], dp[max(0,i-4)] + h);

END FOR

return dp[n];

}

(d)

Modifying the algorithm given in part (b) as follows to know which job to do yourself and in which jobs we need to hire a handyman.

First, Create a 1-d array 'memo' of size, n (1-based indexing) and initialize its elements with -1.

Next, Create another 1-d array 'worker' of size,n (1-based indexing) and initialize its elements with character 'y' representing yourself.

Algorithm :

func(costArr[], startingJobNo){

if(startingJobNo>n)

then return 0

END if

if(memo[startingJobNo] != -1)

then return memo[startingJobNo];

END if

int ans1 = func(costArr, startingJobNo+1) + costArr[startingJobNo]

int ans2 = func(costArr, startingJobNo+4) + h

if(ans2 < ans1)

THEN

for (i = startingJobNo; i<startingJobNo+4 and i<=n; i++)

DO

// mark worker[i] with 'h' representing that we need to hire a mechanic for that job

worker[i] = 'h';

END for

END if

memo[startingJobNo] = min(ans1,ans2);

return memo[startingJobNo];

}

//the worker array will contain 'y' or 'h' representing whether the ith job is to be done 'yourself' or by 'hired man' respectively.

You might be interested in
A BCD code is being transmitted to a remote receiver. The bits are A3, A2, A1, and A0, with A3as the MSB. The receiver circuitry
NARA [144]
<span>BCD only goes from digit 0 (0000) to digit 9 (1001), because for 10 you need two digits, so all you've got to do is make a function that produces high for numbers from 10 (1010) to 15 (1111) as follows:
A3 A2 A1 A0   F
 0    0    0    0    0
 0    0    0    1    0
 0    0    1    0    0
 ...........................
 1    0    0    0    0
 1    0    1    0    1
 1    0    1    1    1
 1    1    0    0    1
 1    1    0    1    1
 1    1    1    0    1
 1    1    1    1    1
 
Then simplify the function: F = A3*A2 + A3*A1 Finally just draw or connect the circuit using NAND</span>
3 0
2 years ago
Type the correct answer in the box. Spell all words correctly.
marysya [2.9K]

Answer:

A Standard Lens

Explanation:

Since David wants to take pictures of people around him and also the objects far away, a standard lens would be fit for that.

3 0
1 year ago
When onboard and facing the bow of a boat where is the port side
topjm [15]

Answer:

im pretty sure this is common sense

Explanation:

3 0
2 years ago
Carmina wants to move a paragraph to the right margin of the document she is working in. She moves her cursor to
MissTica

Answer:

Carmina should use Indent option in order to move a paragraph to the right margin of the margin she is working in.

Explanation:

Indents are used basically to display the blank spaces or distance of the paragraph from the left of right margin.

A simple indent moves the paragraph on either left margin side or right margin side as selected. In order to customize the indents:

  • Click on Home tab.
  • Locate Paragraph group.
  • Click on Indents and Spacing.
  • Now under the Indentation option, from the drop down menu name Special, we can choose an indent to be:

                         1. First Line

                         2. Hanging

  • Moreover, length of the indent can be adjusted.

<h3>I hope it will help you!</h3>
4 0
2 years ago
Read 2 more answers
Which among the following enhances WS-Security to facilitate a mechanism for issuing, renewing, and validating security tokens?
Aleksandr-060686 [28]

Answer:

a. WS-Trust

Explanation:

WS-Trust can be defined as a WS-specification as well as OASIS standard that help to provides extensions to WS-Security, in order to facilitate a mechanism for issuing, renewing, as well as validating of security tokens which is why the aim and objectives of WS-Trust is to help and enable applications to construct trusted SOAP message exchanges.

Nevertheless WS-Trust enables the issuance as well as the dissemination of credentials within several and various trust domains.

5 0
2 years ago
Other questions:
  • Propane also known as LP gas, is often mixed with about _______ percent of other gases, such as butane, propylene, and mercaptan
    13·1 answer
  • Static packet filtering firewalls are limited to ________. inspecting packets for which there are good application proxy filteri
    8·1 answer
  • Thomas has signed a deal with a production house that allows them to use his images on their website. What is required when imag
    5·2 answers
  • Which of the following is not true about VOIP?
    9·1 answer
  • Write a program trapezoid.cpp that prints an upside-down trapezoid of given width and height. However, if the input height is im
    14·1 answer
  • An entrepreneur is opening a computer store in a small town and wants to display a few laptops in the store, but is concerned ab
    11·2 answers
  • As a digital forensics examiner, it’s a good idea to build a list of references for information on privacy laws in other countri
    13·1 answer
  • c Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call FindMax() twice in a
    10·1 answer
  • Prompt
    5·2 answers
  • A police department wants to maintain a database of up to 1800 license-plate numbers of people who receive frequent tickets so t
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!