apples
and the DP matrix dp
with dimensions (k, rows, cols)
.apples
matrix with the number of apples in each sub-rectangle starting from the bottom-right corner.dp[0][row][col]
is 1 if apples[row][col]
is greater than 0, otherwise 0.remain
from 1 to k - 1
.(remain, row, col)
, consider all possible horizontal and vertical cuts.apples
matrix.dp[k-1][0][0]
as the final answer.