20. Cookie Monster

This is Exercise 12 from Java Methods Chapter 20.

Start at the upper left (0,0) of a grid of numbers. Find a path to the lower right corner (cols-1,rows-1) that has the greatest sum. You can only go right and down. Your path is not allowed to contain a square with the number -1.

Data: Read a file describing a 2D array. The first line of the file contains two integers rows and cols. What follows is ROWS lines of data with COLS numbers in each line.

Output: The maximum sum.

Advanced: Report the path taken (an ordered list of coordinates).

4 5
1  2  2  3  4
5 -1  5  7  9
9 -1  9 -1 -1
8 -1 10  9  3

The maximum sum is 1+2+2+5+9+10+9+3 = 41.

Last modified August 18, 2023: 2022-2023 End State (7352e87)