#P1324. 矩形分割
矩形分割
Description
For certain needs, we need to cut an wooden board into small squares.
For a board, we may only cut along a horizontal or a vertical grid line (on the grid lines). The board is non-uniform, so cutting along different lines costs different amounts. Each cut splits one current piece into two pieces. You cannot put pieces together and make a single cut across them to get four pieces; you must cut the two pieces separately.
Given the costs of cutting along each line, find the minimum total cost to partition the whole board into squares.
Input Format
The first line contains and , denoting an board.
The second line contains non-negative integers, representing the costs of cutting along the horizontal grid lines.
The third line contains non-negative integers, representing the costs of cutting along the vertical grid lines.
Output Format
Output a single integer, the minimum total cost.
2 2
3
3
9
Hint
Constraints:
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号