Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA PROGRAMMING - MUST BE DONE RECURSIVELY Problem 3: Picking up coins (1 player 2D) [20 points] Some coins are spread in the cells of
JAVA PROGRAMMING - MUST BE DONE RECURSIVELY
Problem 3: Picking up coins (1 player 2D) [20 points] Some coins are spread in the cells of an m x n board, one coin per cell. A robot, located in the upper left cell of the board, needs to collect as many of the coins as possible and bring them to the bottom right cell On each step, the robot can move either one cell to the right or one cell down from its current location. When the robot visits a cell with a coin, it picks up that coin. Write a recursive function public static int collectCoins2D (int[] [ board, int row, int col) that takes a row and a col of the board as an argument and returns the the maximum number of coins the robot can collect by moving from that cell to the bottom right cell (row m-1 and col-n-1) In the example shown below if the robot starts at the upper left cell of the board (rowcol 0) it can collect 27 coins. (Can you see How?). You may assume that the board is always rectangular or square. If the row/col passed is outside the bounds of the board, return -1 1 9 8 0 6 1 2 8 3 For the above board collectCoins2d (board, 0, 0) must return 27 collectCoins2d (board, 2, 0)) must return 13 collectCoins2d (board, 1, 1)) must return 17 collectCoins2d (board, 2, 2)) must return 3 collectCoins2d (board, 4, 2)) must return -1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started