AcWing 4957. 飞机降落
原题链接
简单
作者:
tyEyyu53
,
2024-04-07 20:48:02
,
所有人可见
,
阅读 2
#include<bits/stdc++.h>
using namespace std;
int n,T,timee,con;
bool ans,st[15];
struct plane
{
int t;
int d;
int l;
}p[15];
bool cmp(const plane&a,const plane&b)
{
return a.t<b.t;
}
void dfs()
{
if (con==n)
{
ans=true;
return;
}
for (int i=1;i<=n;i++)
{
if (st[i])
{
int timee1=timee;
if (timee>p[i].t)
{
int minus = timee-p[i].t;
if (minus > p[i].d) return;
else
{
timee += p[i].l;
st[i]=false;
con++;
}
}
else
{
timee = p[i].t+p[i].l;
st[i]=false;
con++;
}
dfs();
st[i]=true;
timee=timee1;
con--;
}
}
}
int main()
{
cin>>T;
while(T--)
{
cin>>n;
for (int i=1;i<=n;i++) cin>>p[i].t>>p[i].d>>p[i].l;
con=0;
memset(st,true,sizeof(st));
timee=0;
ans=false;
dfs();
if (ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}