You will need to do this to populate your multidimensional array:
for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { for (int k = 0; k < dp[j].length; k++) { Arrays.fill(dp[i][j][k], Integer.MAX_VALUE); } } }
However, you cannot initialize new int[1000][1000][1000][1000] if you have at least 3.64 terabytes . Not to mention how long it will take if you have such a memory.
source share