SUNY Geneseo Department of Computer Science


A Board Game Example of Dynamic Programming

Tuesday, March 5

CSci 242, Spring 2013
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Misc

Dynamic programming problem set (problem set 7) now due next Monday, March 11

I’m out of town Thursday (Mar. 7)

Questions?

Dynamic Programming Problems

Problem 1 from problem set (tile game)

Line of tiles with scores for moving 1 or 2 forward

        tiles( n, s )
            let N[1..n] be a new array        // N[i] will hold maxScore(i)
            N[1] = 0
            N[2] = s[1,2]
            for i = 3 to n
                N[i] = max( s[i-1,i] + N[i-1], s[i-2,i] + N[i-2] )
            return N
        tiles( n, s )
            let N[1..n], M[1..n] be new arrays        // N[i] will hold maxScore(i); M[i] will hold tile to go to i from
            N[1] = 0
            N[2] = s[1,2]
            M[2] = 1
            for i = 3 to n
                if s[i-1,i] + N[i-1] > s[i-2,i] + N[i-2]
                    N[i] = s[i-1,i] + N[i-1]
                    M[i] = i-1
                else
                    N[i] = s[i-2,i] + N[i-2]
                    M[i] = i-2
            return N, M

Problem 3 from problem set (seam carving)?

Removing a chain of pixels from an image

Next

(Tuesday, Mar. 12)

Matrix chain multiplication

Section 15.2


Next Lecture