Madoka's father just reached 11 million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button!
The Bit Button is a rectangular table with nn rows and mm columns with 00 or 11 in each cell. After exploring the table Madoka found out that:
- A subrectangle AA is contained in a subrectangle BB if there's no cell contained in AA but not contained in BB.
- Two subrectangles intersect if there is a cell contained in both of them.
- A subrectangle is called black if there's no cell with value 00 inside it.
- A subrectangle is called nice if it's black and it's not contained in another black subrectangle.
- The table is called elegant if there are no two nice intersecting subrectangles.
For example, in the first illustration the red subrectangle is nice, but in the second one it's not, because it's contained in the purple subrectangle.
Help Madoka to determine whether the table is elegant.
Input
Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤2001≤t≤200) — the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integers n,mn,m (1≤n,m≤1001≤n,m≤100).
The next nn lines contain strings of length mm consisting of zeros and ones — the description of the table.
It is guaranteed that the sum of the values of nn and the sum of the values of mm for all test cases do not exceed 777777.
Output
For each test case print "YES" if its table is elegant or print "NO" otherwise.
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
题意:简化一下就是如果这个图中的联通的1组成的图形不是矩形的话就输出NO,否则输出YES
那么我们找规律简化一下就能发现,最小的情况
如果在一个2*2的矩形里,里面的1的个数相加个数是3的话就不对
那么我们为了方便计算就把字符串数组变为数字数组,
列举每个起点,如果g[i][j]+g[i][j+1]+g[i+1][j]+g[i+1][j+1]==3的话就输出NO
(i的范围是1~n-1,j的范围是1~m-1)
/*
.----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ________ | || | _________ | || | ____ ____ | || | ____ | |
| | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
| | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
| | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
| | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
| | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b){
return b>0 ? gcd(b,a%b):a;
}
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
/*void init(){
int con=0;
for(int i=1;i<=15;i++)con+=i;
}
*/
/*
void sjdhfb(){
int djbhff=0;
for(int dd=1;dd<=4;dd++){
djbhff+=dd;
}
}
*/
//int e[N],ne[N],h[N],idx,w[N];
/*void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
*/
const int N=100+10;
int n,m;
int g[N][N];
void sove(){
cin>>n>>m;
for(int i=1;i<=n;i++){
string s;
cin>>s;
for(int j=0;j<m;j++){
g[i][j+1]=s[j]-'0';
}
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int con=g[i][j]+g[i][j+1]+g[i+1][j]+g[i+1][j+1];
if(con==3){
cout<<"NO"<<endl;
return ;
}
}
}
cout<<"YES"<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie() ,cout.tie() ;
int t=1;
cin>>t;
// init();
// sjdhfb();
// init();
while(t--){
sove();
}
return 0;
}