@dong.li.3344 Hi dong.li.3344. As a rule of thumb, if you have a recurrence relation like T(i, j) = T(i, k) + T(k, j) with i <= k <= j (or something similar), then for the bottom up DP, you have to compute subproblems for subarrays with increasing length, i.e., first compute those of length of 1, then length of 2, next length of 3 and so on. This is because to get T(i, j) where the corresponding subarray has length of j - i + 1, we need information for T(i, i), T(i, i + 1), T(i, i + 2), ..., T(i, j - 1) where the corresponding subarrays have length of 1, 2, 3, ..., up to length of j - i (similar for those subarrays ending at j).

This is why in the outmost loop I have the variable l which indicates the length of the subarray. Inside the loop, I recovered the starting and ending indices of the subarray (that is, index i and j) so it's easier for us to apply the recurrence relation.