fri march 12 lecture dynamic programming er

6
Fri March 12 Lecture 20 Dynamic Programming Suppose we have requests R Er rn with start si finish fi value vi Assume these are sorted by finish t.me f E f E n E fa Given any set of requests 5 define OG to be the score of the optimal solution using the requests in S we want OCR Rk rich Me Question If we know 042 0422 0423 OCR e i can we use this to compute OCR e If so OCR is easy Use OCR to compute OCR Use OCR and 01122 0423 i y Use OCR 01km to compute 042in TR

Upload: others

Post on 20-May-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fri March 12 Lecture Dynamic Programming Er

Fri March 12 Lecture 20

Dynamic ProgrammingSuppose we have requests R Er rnwith start si finish fi value vi Assumethese are sorted by finish t.me

f E f E n E faGiven any set of requests 5 define OGto bethe score of the optimal solutionusing the requests in S we want OCR

Rk rich Me

Question If we know 042 0422 0423OCRe i can we use this to

compute OCRe

If so OCR is easyUse OCR to compute OCRUseOCR and 01122 0423iy

Use OCR 01km to compute042in

TR

Page 2: Fri March 12 Lecture Dynamic Programming Er

r 1 1 Z

re 5B 1 1 Iri 1 1 I

rs 1 1 4ro

0426 he is either in an optimal solutionor it's not

If not Otra O RsIf it is 0 Rg 7 01K

7 0 Ry

OCRa max Oleg 7 t Ryor i

don't take ra do lake ra

Fanctrarcalltree.ORGMax O Rs 7 044

0Rs xCofy B 0441 1 4 23

1 I

Page 3: Fri March 12 Lecture Dynamic Programming Er

Otra ok der

0k 19 0041

04122Okc

Iam been dead

ftp.y A lot of repeat work

MareprecisLet pls be the intervals in s thatdon't conflict with the last elementof S

EI p Rg Er rz.rs no

p Ry Er

Tien 042km ftp.RKIEvktOCplRxD

otherwise

Page 4: Fri March 12 Lecture Dynamic Programming Er

Repeat works just store a value thefirst time you compute it

Memoization

Pseudocodei.memo empty dictionary global variable

function wits list of requests sortedby end time

if S is a key in memoreturn memo6T

if 5 93memo 3 0return O

r last request in Svalue of r

score max w S Er ut wi plsmemoIs Scorereturn scare

Linear t.me OG

This returns the score because

Page 5: Fri March 12 Lecture Dynamic Programming Er

recursively keeping track of the setswould take exponential time

More

To get the solution itself trace backthrough and build it upAt the end of our example thememo diet is

3 O Ry 5Ri 2 Rs 9Rz 5 126 12Rs 5

wi Ra Max Wilks It WilRy12 Max 9 7 52

ra V took ro and called on Ryrs XwitRy Max wilks I t wiCR5 max 5 It 2

wRy X not taking Rywi Rs don't take B xwi Rz do take rz V

Page 6: Fri March 12 Lecture Dynamic Programming Er

rz.ro optimal