程序设计在线评测(Online Judge)

2017年湖南科技大学大学生计算机程序设计竞赛即将于12月举行!

问题 1021. -- 2011市赛题:Matrix

1021: 2011市赛题:Matrix

时间限制: 1 Sec  内存限制: 128 MB
提交: 18  解决: 6
[提交][状态][讨论版]

题目描述

Given an n*m matrix, you are asked to judge if it's fantastic. The rule is: firstly, choose min (n, m) numbers from it, meanwhile you should make sure any two numbers you select will not at the same row or same column. Of course, you may have many different ways to get the numbers. For every way, if the sum of all selected numbers is always same, you may say the matrix is fantastic.

输入

The first line contains an integer T, stands for the number of test cases. (1<=T<=100)

T cases follow, for every case:

The first line contains two integers n and m. (1 <= n, m <= 50)

Then n lines follows, each line contains m integers. Every number in the matrix will between -100000 and 100000.

输出

For every case, if it is a fantastic matrix, output “YES” in one line, otherwise output “NO”.

样例输入

3
2 2
1 3
2 4
2 3
1 1 1
1 1 1
2 1
2
3

样例输出

YES
YES
NO

提示

来源

[提交][状态][讨论版]