Write a method named goldMine
that solves the following "gold mine problem" using dynamic programming.
Suppose you are given a 2-dimensional rectangular grid of integers representing a gold mine.
Each square in the grid stores a positive integer representing the amount of gold on that square.
Imagine a gold miner who begins a journey from any square in the first column.
The miner can take turns moving one square to the right, or one square up-right, or one square down-right.
Your method accepts the mine as a parameter, represented as a rectangular 2D array of integers.
You must find and return an integer representing the maximum amount of gold the miner can collect on any path to the right edge of the mine.
For example, if the mine is the following array:
{{1, 3, 3},
{2, 1, 4},
{0, 6, 4}}
Then your method should return 12
, which is the amount of gold mined by walking on the squares containing the values 2, 6, 4.
You must solve this problem using a bottom-up dynamic programming approach.
Do not use recursion.
You are allowed to construct any data structures (array, list, set, map, etc.) necessary to store the data for your dynamic programming algorithm.