dp with dimensions (m+1) x (n+1) and set all values to 0.i from 1 to m.j from 1 to n.dp[i][j], consider all possible horizontal cuts at height h from 1 to i/2 and update dp[i][j] to the maximum of its current value or the sum of dp[h][j] and dp[i-h][j].w from 1 to j/2 and update dp[i][j] to the maximum of its current value or the sum of dp[i][w] and dp[i][j-w].dp[m][n] as the final answer.