Answer the question
In order to leave comments, you need to log in
How to iterate over moves in 2D space?
There is an array
Or here it is in the picture, I separated the numbers with a comma
Two-dimensional array The
player can move to the right and up
Starts moving in the lower left cell, ends in the upper right.
Is it possible to somehow beautifully sort through all the options for moves from the bottom left to the top right in order to already choose the option when he collects the maximum, and when the minimum
It would be cool to understand how to sort through the moves in two-dimensional space
Answer the question
In order to leave comments, you need to log in
A. This is the 18th task from the Unified State Examination in Informatics.
Exhaustive description, algorithms, etc. available here https://kpolyakov.spb.ru/download/ege18.doc
Can. The problem is solved in O(n^2) by dynamic programming.
Count F(x,y) - the best possible amount to end up in cell (x, y).
Base: in the lower left corner, the answer is the number in that cell; outside - the answer is minus an infinitely bad number (plus infinity if we are looking for a minimum, for example).
Recalculation F(x,y) = a[x,y] + min(F(x+1,y), F(x,y-1)) - we choose from which side it is more profitable to come to this cell.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question