#P3159. [CQOI2012] 交换棋子
[CQOI2012] 交换棋子
Description
There is a black-and-white board with rows and columns. Each time, you may swap the pieces in two adjacent cells (adjacent means sharing an edge or a vertex) to reach a target state. The cell at row , column may participate in at most swaps.
Input Format
The first line contains two integers .
The next lines describe the initial state; each line is a binary string of length , where denotes a black piece and denotes a white piece.
The next lines describe the target state in the same format as the initial state.
The next lines each contain a string of digits from '0' to '9', representing the upper bound on the number of times each cell may participate in swaps.
Output Format
Output a single line with the minimum total number of swaps. If there is no solution, output .
3 3
110
000
001
000
110
100
222
222
222
4
Hint
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号