AcWing 4957. 飞机降落
原题链接
简单
作者:
uehrsirg
,
2023-10-12 21:19:46
,
所有人可见
,
阅读 35
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 10;
int T, n;
int t, d, l;
bool st[N];
struct plane{
int t, d, l;
}p[N];
bool dfs(int num, int last)
{
if (num == n)return true;
for (int i = 0; i < n; i++){
int t = p[i].t, d = p[i].d, l = p[i].l;
if (!st[i] && t + d >= last){
st[i] = true;
if (dfs(num + 1, max(last, t) + l))return true;
st[i] = false;
}
}
return false;
}
int main(){
cin >> T;
while (T--){
cin >> n;
for (int i = 0; i < n; i++){
cin >> t >> d >> l;
p[i] = {t, d, l};
}
memset(st, 0, sizeof st);
if (dfs(0, 0))puts("YES");
else puts("NO");
}
return 0;
}