вход по аккаунту

код для вставкиСкачать
The L-Grid Traversal problem is essentially the same as the example grid
traversal from class. The main differences are that the start and end points are
always the same, movement can only be down or to the right, the user inputs the
dimensions of the grid, and, in the case that the dimensions aren't the same,
subtracts the smaller rectangle from the larger one. Though there are several
ways to handle the subtraction of the smaller rectangle, I chose to use a 2D array
as it seems more intuitive. The array is just a store of whether not any give
coordinate is valid (not subtracted). It can be easily traversed recursively only
passing the x and y coords (first and second dimension indexes). The recursive
logic is as follows:
if out of bounds
return 0
else if in the subtracted rectangle
return 0
else if at the end point (base case)
return 1
else (recursive case)
return number of paths down + number of paths to the right
end if
Пожаловаться на содержимое документа