Problem No. 1. A student has four final exams to prepare for but can allocate on
ID: 3707822 • Letter: P
Question
Problem No. 1. A student has four final exams to prepare for but can allocate only 25 hours of studying time. The expected grade for each course depends on the studying time for its final exam. She estimates her grades as follows: Hours of Stud 15 Course 10 20 25 Simulation Tech. Writin Systems All courses are 3 credits each. She wishes to maximize her expected grade point total where A-4, B-3, C-2, D-1 and F-0. Use dynamic programming to determine how the student should allocate her studving time.Explanation / Answer
s=[]
m=[[0,1,2,3,4,4],[0,2,2,3,3,4],[0,2,3,3,4,4],[0,3,3,3,3,4]]
for i in range(0,4):
l=[]
for j in range(0,6):
l.append(0)
s.append(l)
for j in range(0,6):
s[0][j] = m[0][j]
for i in range(1,4):
for j in range(0,6):
max = 0
for k in range(0,j+1):
# This is the score you could get by spending j time, spending
# k time on this exam and j-k time on the previous exams.
Grade = s[i-1][j-k] + m[i][k]
if Grade > max:
max = Grade
s[i][j] = max
print s
Where S[i][j] represent the best score we can achieve by spending j unit of time on the first i exams. We can calculate S[i][j] by looking at S[i-1][k] for each value of k. For each element of S, remember the value of k from the previous row that gave the best result. The answer to what the best score for studying all exams in time T is just S[n][T], and we can use the values of k that we remembered to determine how much time to spend on each exam.
M be a matrix of n rows and T columns.
M[i][j] correspond to the score obtained by spending j units of time on exam i.
If we run our code then the final matrix s will be
s = [[0, 1, 2, 3, 4, 4], [0, 2, 3, 4, 5, 6], [0, 2, 4, 5, 6, 7], [0, 3, 5, 7, 8, 9]]
so the max points = s[3][5] = 9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.