n = int(input())
for i in range(n):
m = int(input())
M, temp = [], []
for j in range(m):
temp = list(map(int, input().split()))
M.append(temp)
# 用flag表示是否上三角矩阵,好处在于一旦最内层循环被break,可根据flag值终止最外层循环
flag = 1
for k in range(m):
if flag == 0:
break
for j in range(k):
if M[k][j] != 0:
flag = 0
break
if flag == 0:
print('NO')
else:
print('YES')
3:7-20 判断上三角矩阵
最新推荐文章于 2021-12-14 20:41:48 发布