# (Solved) : Consider Following Game Given Sequence N Positive Numbers A1 A2 Initially Colored Black Q40180158 . . .

\$9.00 Consider the following game. You are given a sequence of n positive numbers (a1, A2, …, An). Initially, they are all colored black. At each move, you choose a black number ak and color it and its immediate neighbors (if any) red (the immediate neighbors are the elements ak-1, ak+1 ). You get ak points for this move. The game ends when all numbers are colored red. The goal is to get as many points as possible. (a) Describe and analyze an efficient dynamic programming algorithm for this problem that runs in O(n) and returns optimal solutions. Show transcribed image text Consider the following game. You are given a sequence of n positive numbers (a1, A2, …, An). Initially, they are all colored black. At each move, you choose a black number ak and color it and its immediate neighbors (if any) red (the immediate neighbors are the elements ak-1, ak+1 ). You get ak points for this move. The game ends when all numbers are colored red. The goal is to get as many points as possible. (a) Describe and analyze an efficient dynamic programming algorithm for this problem that runs in O(n) and returns optimal solutions. 