Row-major vs. Column-major access to arrays
By storing the data in the correct order in your array, you can speed up access to the array.
If you’re iterating and then , don’t create an array as in each iteration, you’ll have to jump DP[j].length elements to get to DP[j][i+1]. This forces the cache to be fetched more often.
In row-major access, the CPU can just access the next memory location.