Classic Dynamic Programming XII
This type of DP is the one that still doesn't come naturally to me (and yes, I took a look at the hints!). The combination of different XORs along the paths are indeed exponential, but the key is to see that the possible values of the cells are all < 1024. Every XOR then will land somewhere between 0-1023. With that information, we can DP it by using a matrix of DP[rows][cols][1024], and keep track of any path that lights up any of the bits between 0-1023. The cleanness of the code is striking, it is very "symmetrical" when it is set and done, however the mental model is still non-intuitive (IMO) since you're using the values of grid as indexes of the DP. Code is down below, cheers, ACC. Minimum XOR Path in a Grid - LeetCode You are given a 2D integer array grid of size m * n . You start at the top-left cell (0, 0) and want to reach the bottom-right cell (m - 1, n - 1) . At each step, you may move either ri...