write a program to control a digger. For your task, you have been given a 'map' of all the underground resources in the mine. This map comes as a two-dimensional integer array. The array has n rows and k columns. Each integer is between zero and one hundred (inclusive). This array represents a grid map of the mine – with each row representing a different height level. Each square in the grid can contain valuable resources. The value of these resources can go from zero (no resources) to 100 (max resources). The grid maps the resources just below the surface, and down to the lowest diggable depths. The digger starts at the surface (so, just on top of the topmost row in the grid)—at any horizontal position between 1 and k. The digger cannot dig directly downwards, but it can dig diagonally in either direction, left-down, or right-down. In its first time-step, it will dig onto the first row of the grid. In its second time-step, it'll hit the second row, and so on. When the digger reaches row number n, it has to be air-lifted out of the mine, and is no longer usable. Every time the digger hits a square with resources in it, it collects those resources. We want to find out the maximum number of resources a digger can collect from this mine in one run. Let’s implement a recursive solution to this problem, reducing the problem of finding the maximum number of resources reachable from any point in the grid to finding the maximum number of resources that can be achieved by moving down-left, then finding the maximum number of resources by moving down-right, and selecting the highest of the two. write a method called maxResources. This method will take a two-dimensional integer array as input and produce one integer output. The input represents the grid map of the mine and the integer output should be equal to the maximum amount of resources that can be collected by a digger in a single run. We want to have a method that is implemented recursively, so it may be useful to implement a version with additional inputs to allow it to keep track of which cell it is looking at. The recursive formula should define maxResources for a particular coordinate (x,y) as the sum of the number of resources in (x,y) and the value of maxResources from either coordinate (x+1, y+1) or coordinate (x-1, y+1), whichever is higher public static int maxResources(int[][] mine) { return -1; }
You have been hired at an open-air mine. You are to write a program to control a digger. For your
task, you have been given a 'map' of all the underground resources in the mine. This map comes as a
two-dimensional integer array. The array has n rows and k columns. Each integer is between zero
and one hundred (inclusive). This array represents a grid map of the mine – with each row
representing a different height level. Each square in the grid can contain valuable resources. The
value of these resources can go from zero (no resources) to 100 (max resources).
The grid maps the resources just below the surface, and down to the lowest diggable depths. The
digger starts at the surface (so, just on top of the topmost row in the grid)—at any horizontal
position between 1 and k. The digger cannot dig directly downwards, but it can dig diagonally in
either direction, left-down, or right-down. In its first time-step, it will dig onto the first row of the
grid. In its second time-step, it'll hit the second row, and so on. When the digger reaches row
number n, it has to be air-lifted out of the mine, and is no longer usable. Every time the digger hits a
square with resources in it, it collects those resources.
We want to find out the maximum number of resources a digger can collect from this mine in one
run. Let’s implement a recursive solution to this problem, reducing the problem of finding the
maximum number of resources reachable from any point in the grid to finding the maximum
number of resources that can be achieved by moving down-left, then finding the maximum number
of resources by moving down-right, and selecting the highest of the two.
write a method called maxResources. This method will take a two-dimensional integer array as
input and produce one integer output. The input represents the grid map of the mine and the
integer output should be equal to the maximum amount of resources that can be collected by a
digger in a single run.
We want to have a method that is implemented recursively, so it may be useful to implement a
version with additional inputs to allow it to keep track of which cell it is looking at.
The recursive formula should define maxResources for a particular coordinate (x,y) as the sum of the
number of resources in (x,y) and the value of maxResources from either coordinate (x+1, y+1) or
coordinate (x-1, y+1), whichever is higher
Step by step
Solved in 4 steps with 3 images