SZOJ_L49

Judge Info

  • Memory Limit: 65536KB
  • Case Time Limit: 1000MS
  • Time Limit: 1000MS
  • Judger: Normal

Description

00 knows a new kind of square matrix spiral123, which has the following properties: • its elements are from the {0, 1, 2, 3} set; • each row and column contains each of the values 1, 2 and 3, exactly once and all the other values are 0; • starting from the upper-left corner going right, moving in spiral, show as followed, the non-zero values will appear in the following order 1, 2, 3, 1, 2, 3, ... , 1, 2, 3.

 

For example a 5x5 spiral123 matrix is the above. Now 00 gives you a square matrix, please determine whether it is a spiral123.

Input

The first line of input contains T (1<=T<=500), the number of test cases. For each test case the first number is n (1<=n<=200), indicates the size of the input matrix. The next N line is the matrix and each line exactly has N integer. Every integer in the matrix is non-negative.

Output

For each test case, print “YES”, if it is spiral123 matrix, otherwise print “NO” in a line.

Sample Input

1 
5 
0 1 0 2 3
0 2 3 0 1
1 3 0 0 2
3 0 2 1 0
2 0 1 3 0

Sample Output

YES

开始理解题意为123123123...顺序,交了WR。重新看题目,发现123123...123,因此觉得应该呀以3结尾,修改再提交,又WR。尼玛,再看题目,
看到“contains each of the values 1, 2 and 3”,觉得每一行没一列应该不能全为0,即应该至少包含123其中一个(如一行00100),因此再修改,提交,又WR。。。奔溃。
接着去做数据库作业去了,晚上听德颖说每行每列都要包含123至少一个,尼玛,原来是3个都要出现至少一次,(即一行至少01002300)。改了,提交,瞬间过了,水题也不水啊,英语是一道硬伤。
posted @ 2013-05-14 22:45  nextone  阅读(148)  评论(1编辑  收藏  举报