第十四届蓝桥杯省赛C/C++大学B组真题-飞机降落


思路:根据数据范围N<=10猜测用DFS+剪枝,因为菜狗不会状压dp。根据题目,一般这种飞机的题都会用到贪心的思想。思想是每架飞机都要卡极限最早降落时间,从而保证后面的飞机能够有充足时间降落。
代码参考博客@MQy大佬有详细解答

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
struct Plane {
    int t, d, l;
}p[N];

bool vis[N];
bool dfs(int pos, int last){
    if(pos == n) return true;
    for(int i = 0; i < n; ++i){
        int t = p[i].t, d = p[i].d, l = p[i].l;
        if(!vis[i] && t + d >= last){
            vis[i] = true;
            if(dfs(pos + 1, max(last, t) + l)) return true;
            vis[i] = false;
        }
    }
    return false;
}

int main(void){
    int T;
    cin >> T;

    while(T--){
        scanf("%d", &n);
        for(int i = 0; i < n; ++i){
            int t, d, l;
            scanf("%d%d%d", &t, &d, &l);
            p[i] = {t, d, l};
        }

        memset(vis, 0, sizeof vis);
        if(dfs(0,0)) puts("YES");
        else puts("NO");
    }

    return 0;
}
相关推荐
aaasssdddd96几秒前
python和c
c语言·开发语言·python
黑不溜秋的28 分钟前
C++ 语言特性29 - 协程介绍
开发语言·c++
一丝晨光33 分钟前
C++、Ruby和JavaScript
java·开发语言·javascript·c++·python·c·ruby
￴ㅤ￴￴ㅤ9527超级帅1 小时前
LeetCode hot100---二叉树专题(C++语言)
c++·算法·leetcode
_GR1 小时前
每日OJ题_牛客_牛牛冲钻五_模拟_C++_Java
java·数据结构·c++·算法·动态规划
凯子坚持 c1 小时前
C语言复习概要(三)
c语言·开发语言
无限大.1 小时前
c语言200例 067
java·c语言·开发语言
无限大.1 小时前
c语言实例
c语言·数据结构·算法
Death2002 小时前
Qt 中的 QListWidget、QTreeWidget 和 QTableWidget:简化的数据展示控件
c语言·开发语言·c++·qt·c#
六点半8882 小时前
【C++】速通涉及 “vector” 的经典OJ编程题
开发语言·c++·算法·青少年编程·推荐算法