Java calculates the range of motion of the robot

The motion range of the robot java version, the specific contents are as follows

There is a square with M rows and N columns on the ground. A robot starts to move from the grid with coordinates 0 and 0. Each time, it can only move one grid in the left, right, upper and lower directions, but it cannot enter the grid where the sum of digits of row coordinates and column coordinates is greater than k. For example, when k is 18, the robot can enter the grid (35,37) because 3 + 5 + 3 + 7 = 18. However, it cannot enter the grid (35,38) because 3 + 5 + 3 + 8 = 19. How many grids can the robot reach?

Problem solving ideas:

1. First judge whether the current position meets the entry conditions. If the entry conditions are met, Continue to judge the four surrounding positions (except the boundary). If not, it indicates that the current position is selected incorrectly. 2. In each attempt, declare a flag array to record the accessed positions. 3. There are three conditions for the current attempt to continue: the coordinates are legal in the matrix, the coordinates meet the entry conditions, and the coordinate positions have not been accessed.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>