老规矩,先看数据范围,知枚举,时间复杂度(t*n**2)
注意:dfs一定要留个心,让它加个成功运行的条件
def dfs(time, idx):
if ls[idx][1] < time: return
if vis[idx] == 1: return
vis[idx] = 1
if sum(vis) == n+1:
return True
time = max(time, ls[idx][0]) + ls[idx][2]
for nex in range(1, n+1):
if dfs(time, nex):
return True
vis[idx] = 0
t = int(input())
for _ in range(t):
n = int(input())
ls = [[0,0,0]]
vis = [0]*(n+1)
for i in range(n):
t, d, l = map(int,input().split())
ls.append([t,t+d,l])
if dfs(0, 0): print('YES')
else: print('NO')