P
Patricia Shanahan
Luc The Perverse wrote:
....
You got it. There is an optimization that reduces the memory cost,
but you have a dynamic programming solution to the problem. And you have
the really big savings from exponential to linear increase in time and
memory as the number of moves increases.
I think, more than ever after seeing this, that you would benefit from
reading a book on algorithm design.
Patricia
....
....WAIT!
I think I got it (I'm not meaning to imply that you didn't help) - and I
didn't look at anything.
Let's say there are NxN squares, and there are x number of moves.
I can make the square x, y be represented as an integer 0..N * N - 1
So I create a 2D array [N*N][x] of longs which will represent the sum of the
number of unique paths to the given point.
You got it. There is an optimization that reduces the memory cost,
but you have a dynamic programming solution to the problem. And you have
the really big savings from exponential to linear increase in time and
memory as the number of moves increases.
Hey thanks everyone. This is more than just a single problem or some points
on a practice problem that doesn't matter anyway. I'm learning how to do
this, and becoming a better programmer - and that is important to me.
Learning new abstract concepts, and having exciting revelations is actually
(though sadly) a bit of a rarity for me.
I think, more than ever after seeing this, that you would benefit from
reading a book on algorithm design.
Patricia