AcWing 4957. 飞机降落
原题链接
简单
作者:
小王子_19
,
2024-04-09 19:00:22
,
所有人可见
,
阅读 2
C++ 代码
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 20;
int T, n;
struct Plain
{
int t, d, l;
}p[N];
bool st[N];
bool dfs(int u, int last)
{
if (u == 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(u + 1, max(last, t) + l)) return true;
st[i] = false;
}
}
return false;
}
int main()
{
cin >> T;
while (T -- )
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ )
scanf("%d%d%d", &p[i].t, &p[i].d, &p[i].l);
memset(st, 0, sizeof st);
if (dfs(0, 0)) printf("YES\n");
else printf("NO\n");
}
return 0;
}