#P9900. 『PG2』消除萝卜 B
『PG2』消除萝卜 B
Problem Description
There are carrots arranged in two columns. Carrots are either white or red. We use to represent whether the carrot in row , column is white or red.
Each time, you may pay a cost of to choose a position that currently has a carrot, and remove all carrots in the 4-connected maximal connected component consisting of carrots of the same color as that chosen carrot. After that, if a carrot is in row and the corresponding position in row has no carrot, then it will fall to row .
Also, you may pay a cost that is initially to choose and shift all carrots in column upward (), and place a red carrot, i.e. , into row , column (). After this, the cost of this operation increases by each time it is used.
Find the minimum total cost to remove all carrots.
Input Format
The first line contains a positive integer , the number of rows of carrots.
The next lines each contain two integers, which are .
Output Format
Output one integer in one line, representing your answer.
4
0 1
0 1
0 1
0 1
2
6
1 0
1 0
0 1
0 1
1 0
1 0
3
Hint
For all test points, , , and it is guaranteed that .
This problem uses bundled tests.
$\sf subtask \ 1: n\leq10 \ \ \ \ \ \ \ \ \ \ \ 30pts$
Translated by ChatGPT 5