Question: python P2 (25pt): Let's play a game. You have a nxn square grid. Initially you must place a token on a square in the first

 python P2 (25pt): Let's play a game. You have a nxn

python

P2 (25pt): Let's play a game. You have a nxn square grid. Initially you must place a token on a square in the first row. In each turn, you move your token to one square to the right, or one square down. The game ends when you move your token out of the board. Each square on the grid has a numerical value, which could be positive, zero, or negative. You start with O score. Whenever the token lands on square, you add its value to your score. You try to score as many points as possible. Describe an efficient algorithm to compute the maximum score, given a board A[i...n][1...]. Analyze its time complexity. For example, given the grid below, and placing initial token on Ist row 2nd column, and moving down, down, right, down, down, the game ends and you have score -9 (which is not the max- imum possible). Backtracking gets you 15pt. Dynamic Programming may get full credit. Greedy algorithm must come with proof of correctness. - 1 7-8 10 -5 -4 -9 8 -6 0 5 - 2 -6 -6 7 -7 7 -3 -3 I 6 4 [hint: Try dynamic programming. What's the definition of your table? What's the recurrence + base cases? What's a proper evaluation order? There's no need for pseudo code if you answer this three questions correctly.] P2 (25pt): Let's play a game. You have a nxn square grid. Initially you must place a token on a square in the first row. In each turn, you move your token to one square to the right, or one square down. The game ends when you move your token out of the board. Each square on the grid has a numerical value, which could be positive, zero, or negative. You start with O score. Whenever the token lands on square, you add its value to your score. You try to score as many points as possible. Describe an efficient algorithm to compute the maximum score, given a board A[i...n][1...]. Analyze its time complexity. For example, given the grid below, and placing initial token on Ist row 2nd column, and moving down, down, right, down, down, the game ends and you have score -9 (which is not the max- imum possible). Backtracking gets you 15pt. Dynamic Programming may get full credit. Greedy algorithm must come with proof of correctness. - 1 7-8 10 -5 -4 -9 8 -6 0 5 - 2 -6 -6 7 -7 7 -3 -3 I 6 4 [hint: Try dynamic programming. What's the definition of your table? What's the recurrence + base cases? What's a proper evaluation order? There's no need for pseudo code if you answer this three questions correctly.]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!