I have been presented with a problem I am supposed to use dynamic programming on, but I am really stuck. I really want to understand exactly how to approach this.
The problem is as follows: You are given an array of size N, each entry represents a city with a given value. At each round, you must choose where to build a wall. The "enemy" then chooses which side (either east or west) to attack from, destroying all of the cities up until the wall. You only collect value from the cities that still exist. The enemy destroys cities optimally meaning it always minimizes the amount of value you can get at the END of the game (not minimized per round, greedily).
A quick example:
Array: 8, 6, 2, 4, 2
1st Round - Best option is to build between city of value 6 and of value 2. The enemy attacks from the west which results in value of 8 to be collected.
2nd Round - Best option is to build between city of value 2 and of value 4. The enemy attacks from the east which results in value of 2 to be collected.
Total value for this game was 10.
I'm looking to find a recursive formula for the maximum possible value I can get in each game. I want to use this recursive formula to create a dynamic programming algorithm. Any help would be appreciated.