Question: JAVA Program Bunny is jumping around an n x n sized grid collecting carrots. On each square of the grid, there is a three-dimensional vector,

JAVA Program

Bunny is jumping around an n x n sized grid collecting carrots. On each square of the grid, there is a three-dimensional vector, , representing the x and y displacement of a jump, as well as the number of 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: 1) The first line contains integer n (example :3)

2) the length and width of the grid. (Three nxn sized grids of integers will follow.)

The first grid contains the x (|x| < n) values, the second contains the y (|y| < n) values, and the third contains the c (0 < 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. */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!