问题3216--Matrix Game

3216: Matrix Game

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

At the start of the matrix game, we have an n * m chessboard in which each grid is painted alternatively in white or black. Every time, we can apply one of the two following operations: Row flip operation: we can change the color of every grid in a single row. Column swap operation: we can swap two columns (i.e., switch the colors between corresponding grids). The task of the problem is, determine whether it’s possible to reach the target from the original chessboard by applying the two operations several times. Print ‘Yes’ or ‘No’ for each case.

输入

There are several test cases. For each case, there are two integers n and m in the first line (1 ≤ n, m ≤ 100), followed by two n * m 0/1 matrixes (0 stands for white color and 1 stands for black color) which are the original chessboard and the target chessboard respectively. The input ends up with two negative numbers, which should not be processed as a case.

输出

For each test case, print ‘Yes’ or ‘No’ to tell whether it’s possible to reach the target.

样例输入 Copy

2 2
1 1
1 0
0 0
0 1
2 2
1 1
1 0
0 0
0 0
-1 -1

样例输出 Copy

Yes
No

来源/分类

multi