蓝桥14/B/3/飞机降落

点击查看代码
#include<bit/stdc++.h>
using namespace std;

const int N = 15;
int n, t[N], d[N], l[N];
bool st[N];
//状态定义
bool dfs(int u, int time) {
    //终止条件
    if (u == n) return true; // 所有飞机成功降落
    
    //枚举
    for (int i = 0; i < n; i++) {
        //选择
        if (!st[i] && t[i] + d[i] >= time) {
            st[i] = true;
            //递归
            if (dfs(u + 1, max(time, t[i]) + l[i])) return true;
            //回溯
            st[i] = false; 
        }
    }
    return false;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t[i] >> d[i] >> l[i];
        st[i] = false; //清空标记数组
    }
    // 从第 0 架飞机、时间 0 开始搜
    cout << (dfs(0, 0) ? "YES\n" : "NO\n");
}

int main() {
    
    cin.tie(0)->sync_with_stdio(0); 
    
    int tc; 
    cin >> tc;
    while (tc--) solve();
    
    return 0;
}
posted @ 2026-03-10 00:16  AnoSky  阅读(0)  评论(0)    收藏  举报