Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 986 Bytes

0071.飞机降落.md

File metadata and controls

68 lines (52 loc) · 986 Bytes

71. 飞机降落

题目链接

C

C++

#include<bits/stdc++.h>

using namespace std;

const int N=10;

int n;
struct Plane
{
    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()
{
    int T;cin>>T;
    
    while(T--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            int t,d,l;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;
}

Java

Python

JS

Go