Question: Java Program: Benny the Bunny is jumping around an n x n sized grid collecting carrots. On each square of the grid, there is a
Java Program:
Benny the Bunny is jumping around an n x n sized grid collecting carrots.
On each square of the grid, there is a three-dimensional vector,
carrots, c, for that square. Whenever Benny lands on one of these squares, he collects all c carrots and jumps into the air, traveling x squares in
the x-direction (to the right) and y squares in the y-direction (downward). Once Benny lands, he collects more carrots, jumps again and lands on
another square, and keeps on jumping, landing, and collecting carrots until he jumps outside the grid or lands on a previously encountered square.
Help Benny determine the maximum number of carrots he can collect, given that he starts on one of the spaces on the grid.
Input:
Scan the text file name containing input data.
Enter name of text file: 1.txt ENTER text file example

The first line contains integer n ( the length and width of the grid).
Three nxn sized grids of integers will follow. The first grid contains the x (|x|
and the third contains the c values.
Output:
Print m, the maximum number of carrots Benny can collect if he is allowed
to start on any space on the grid.
Example:
Input:
3
-1 1 0
1 1 2
-1 1 -2
1 2 0
0 -1 2
-2 -1 2
4 8 6
8 1 3
5 7 1
Output:
15
Explanation:
By starting at (0, 1), i.e. left edge, one down, Benny jumps to (1, 1),
(2, 0), then (2, 0) again, collecting 8 + 1 + 6 = 15 carrots total, the
maximum amount out of all possible paths.
*/
1.txt - Notepad File Edit Format View Help 31 1 11 2 10 1 11 0 10 0 01 2 01 2 31 5 67 8 9 1.txt - Notepad File Edit Format View Help 31 1 11 2 10 1 11 0 10 0 01 2 01 2 31 5 67 8 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
