#icpc2013autumni. [icpc2013autumn_i]Overwriting Game
[icpc2013autumn_i]Overwriting Game
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You have a rectangular board with square cells arranged in rows and columns. The rows are numbered through from top to bottom, and the columns are numbered through from left to right. The cell at the row and the column is denoted by . Each cell on the board is colored in either Black or White.
You will paint the board as follows:
-
Choose a cell and a color , each uniformly at random, where , , and .
-
Paint the cells with the color for any and .
Here's an example of the painting operation. You have a board with the coloring depicted in the left side of the figure below. If your random choice is the cell and the color Black, the board will become as shown in the right side of the figure. cells will be painted with Black as the result of this operation. Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell in this example.
Fig: An example of the painting operation
Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring. Write a program to calculate the expected total number of painted cells in the sequence of operations.
Input
The input consists of several datasets. The number of datasets is at most .
The first line of each dataset contains two integers and (), the numbers of rows and columns of the board respectively. Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring. A coloring configuration is described in lines, each of which consists of characters. Each character is either B or W, denoting a Black cell or a White cell, respectively. There is one blank line between two configurations, and also after each dataset. You can assume that the resulting expected value for each dataset will not exceed .
The input is terminated by a line with two zeros, and your program should not process this as a dataset.
Output
For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than .
Sample Input
1 2
BB
WW
2 1
B
W
B
W
2 2
BW
BW
WW
WW
3 4
BBBB
BBBB
BBBB
WWWW
WWWW
WWWW
5 5
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBWB
BBBBB
BWBBB
BBBBB
0 0```
### Output for the Sample Input
```plain
6.0000000000
0.0000000000
12.8571428571
120.0000000000
23795493.8449918639```
* * *
### Source Name
[JAG Practice Contest for ACM-ICPC Asia Regional 2013](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%CC%CF%B5%BC%C3%CF%B6%E8%CD%BD%C1%AA)
* * *