4 ms·
>A logarithmic time solution involving adjacency matrices, matrix multiplication, and binary decomposition of numbers. can you post a link to this solution? so
by mlevental 8y ago
>A logarithmic time solution involving adjacency matrices, matrix multiplication, and binary decomposition of numbers.
can you post a link to this solution? sounds cool.
edit: lol i just realized this is simply multiplying the adjacency matrix and what you mean by binary decomposition of numbers is just exponentiation by squaring. it's funny now that i realized i'll probably never figure out the dp solution.
edit2: got it. number of length n paths for some key u is sum of n-1 paths across "knight neighbors" of u. base case is length 1 path which is just # of neighbors.
it's funny this problem is designed in a particular way. using the keypad instead of a chessboard lets you write down the graph by hand rather than actually procedurally generating it (which is awkward with lots of literal edge conditions to check).
- chillee 8y agoYeah this is one of the "standard" uses for matrix multiplication. Another one is calculating the N-th fibonacci number in logarithmic time (or any linear recurrence).