#1296. Problem C. 黑白立方格
Problem C. 黑白立方格
Given a cubic lattice of size such that each lattice point is either white or black. The coordinates of the lattice point are all positive integers. Let the cost of flipping the color of lattice point be . Find the minimum cost to flip the colors of lattice points such that the bottom left corner is black, the top right corner is white, and any two different lattice points and satisfy at least one of the following conditions.
Input
The first line includes three integers (, ), denoting the size of the lattice. Each of the next lines contains a string of length that only consists of \t{B} and \t{W}. The initial color of lattice point is the -th character of the line. If the character is \t{B}, it means the color of the lattice point is black, otherwise it is white. Each of the next lines contains non-negative integers not greater than . The cost of flipping the color of lattice point is the -th integer of the line.
Output
Output the minimum cost.
Example
2 2 2
WW
WW
BB
BB
1 1
1 1
2 2
2 2
5