Question

In: Computer Science

Shindler gives lots of homework assignments, each of which have an easy version and a hard...

Shindler gives lots of homework assignments, each of which have an easy version and a hard version1. Each student is allowed, for each homework, to submit either their answer to the easy version (and get ei > 0 points) or the hard version (and get hi > 0 points, which is also guaranteed to always be more than ei) or to submit neither (and get 0 points for the assignment). Note that ei might have different values for each i, as might hi. The values for all n assignments are known at the start of the semester.

The catch is that the hard version is, perhaps not surprisingly, more difficult than the easy version. In order for you to do the hard version, you must have not done the previous assign- ment at all: neither the easy nor the hard version (and thus are more relaxed, de-stressed, etc). Your goal is to maximize the number of points you get from homework assignments over the course of the semester. Give an efficient dynamic programming algorithm to determine the largest number of points possible for a given semester’s homework choices.

Solutions

Expert Solution

To maximize the student's scores, we can model the recurrence as:

The pseudocode for the algorithm can be given as:

The initialization condition for dparray is mentioned in the comments of the code. (In both the textual as well as the screenshot format)

Code in python:

easy_list = [5,10,10,15,20]

hard_list = [10,12,15,25,30]

dparr = [0]*len(easy_list) #intitialize the dparray with the size of easylist and all will have 0 value

dparr[0] = hard_list[0]     #This is given as the first condition because, the user will always be relaxed and de-stressed at the beginning of the term, hence will select the hard question.

dparr[1] = max(dparr[0] + easy_list[1], hard_list[1])  #This is the second condition because for the second day he can either do the hard question that day andskip the earlier question

                                                       #Otherwise he can also do the question of the previous day and complete the easy one for this day.

for i in range(2,len(easy_list)):

    dparr[i] = max(dparr[i-1] + easy_list[i], dparr[i-2] + hard_list[i])    

print(dparr[len(dparr) - 1])

Code Screenshot:

Output Screenshot:

Please refer to the screenshot of the code to understand the indentation of the code".


Related Solutions

6. Students at a local university believe that their statistics instructor gives them homework assignments just...
6. Students at a local university believe that their statistics instructor gives them homework assignments just to punish them. They wonder if there is any relationship between the number of optional homework problems they do during the semester and their final course grade. They decide to keep track of the number of these problems completed during the course of the semester. At the end of the class each student’s total is recorded along with their final grade.   Problems Course Grade...
Critical Thinking Use the data set which shows student grades and the number of homework assignments...
Critical Thinking Use the data set which shows student grades and the number of homework assignments missed. You can use the pivot table feature in excel to make a crosstabulation or contingency table as a first step. Choose the best statement below. Grades and homework data, click here https://drive.google.com/file/d/1nDzzuY-pXeRqisc9sKpuKfXOMHXkBeLv/view?usp=sharing A. Passing the class appears to be strongly and negatively related to the number of missed homeworks. The probability of not passing the class is fairly low for students that turn...
Most video games have several difficulty settings, from "Easy" to "Hard" (many of these have very...
Most video games have several difficulty settings, from "Easy" to "Hard" (many of these have very colorful names). A video game designer wants to determine how to structure the difficulty levels for a new game so that the average time it takes the typical player to play through "Hard" mode is longer than the time to play through "Easy" mode. A sample (Group 1) of 15 typical players took an average of 5.3 hours to complete the game on "Hard",...
You have been collaborating with a colleague in writing a report, the final version of which...
You have been collaborating with a colleague in writing a report, the final version of which is due in three days. You have completed your part of the report by yesterday's draft deadline you both agreed to, but you've received nothing from your colleague. You send him an email asking when you will get his work and CC (copy) the message to your manager. What is the most likely secondary purposeof your message? Question options: to let your boss know...
I have homework on this but I am not sure how to solve it and which...
I have homework on this but I am not sure how to solve it and which formula to use in excel, can u please help me Rebecca is considering buying a 2019 Genesis G70 costing $37,900 and finds that the retaining values of the vehicle over the next four years are as follows: Percent of the total value retained after 24 months: 71% Percent of the total value retained after 48 months: 53% If her interest rate is 5% compounded...
Consider a population in which there are no deaths and each individual independently gives birth at...
Consider a population in which there are no deaths and each individual independently gives birth at rate 1. Independently of the other events, immigrants arrive in the population at times of a Poisson process with rate 2. Let X(t) denote the number of individuals in the population at time t. The pure birth process (X(t),t ≥ 0) is called a Yule process with immigration. (a) Give the birth rates for the process (X(t),t ≥ 0). (b) Find P(X(2) = 1|X(0)...
How does the governmental organization for which you have been working with in your assignments structure...
How does the governmental organization for which you have been working with in your assignments structure its budget into funds? the organization is the city of Dallas
I’m having a very hard time. I have to do a poster pensebtation which I have...
I’m having a very hard time. I have to do a poster pensebtation which I have no clue how to do on Identify the key mental health disorders that affect the elderly. Determine how these key mental disorders differ across racial, ethic, gender, and socioeconomic lines. Thank you,
I’m having a very hard time. I have to do a poster pensebtation which I have...
I’m having a very hard time. I have to do a poster pensebtation which I have no clue how to do on Identify the key mental health disorders that affect the elderly. Determine how these key mental disorders differ across racial, ethic, gender, and socioeconomic lines.
Do freshmen, sophomores, juniors and seniors have the same mean number of hours of homework each...
Do freshmen, sophomores, juniors and seniors have the same mean number of hours of homework each week? Test at the alpha = .05 level with the following random sample. Freshmen: { 15, 12, 20, 25} Sophomores: {20, 12, 14, 15} Juniors: {25, 10, 10, 15} Seniors: {15, 12, 12, 14, 9}             Using the given alpha and p-value, what is your conclusion in plain English? a) There is not enough evidence to suggest that the population means are equal. b)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT