题海拾贝:P9241 [蓝桥杯 2023 省 B] 飞机降落

Hello大家好!很高兴我们又见面啦!给生活添点passion,开始今天的编程之路!

我的博客: <但凡.

我的专栏: 《编程之路》《数据结构与算法之美》《题海拾贝》

欢迎点赞,关注!

1、题目

2、题解

cpp 复制代码
#include<iostream>
#include<cstring>
using namespace std;
const int N = 15;
int T, n;
int t[N], d[N], l[N];
bool st[N];
bool dfs(int pos, int end)//第几加以及结束时间
{
	if (pos > n) return true;

	for (int i = 1;i <= n;i++)
	{
		if (st[i] == true) continue;
		if (end > t[i] + d[i]) continue;
		int newend = max(t[i], end) + l[i];
		st[i] = true;
		if (dfs(pos + 1, newend)) return true;
		st[i] = false;
	}
	return false;
}
int main()
{
	cin >> T;
	while (T--)
	{
		memset(st, 0, sizeof st);
		cin >> n;
		for (int i = 1;i <= n;i++)
		{
			cin >> t[i]>>d[i]>>l[i];
		}
		if (dfs(1, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

好了,今天的内容就分享到这,我们下期再见!

相关推荐
贾斯汀玛尔斯20 小时前
每天学一个算法--LSM-Tree(Log-Structured Merge Tree)
java·算法·lsm-tree
浅念-1 天前
刷穿LeetCode:BFS 解决 Flood Fill 算法
数据结构·c++·算法·leetcode·职场和发展·bfs·宽度优先
做cv的小昊1 天前
【TJU】研究生应用统计学课程笔记(8)——第四章 线性模型(4.1 一元线性回归分析)
笔记·线性代数·算法·数学建模·回归·线性回归·概率论
贾斯汀玛尔斯1 天前
每天学一个算法--倒排索引(Inverted Index)
算法·inverted-index
小e说说1 天前
打破偏科困境:这些学习软件助孩子重燃学习热情
算法
月昤昽1 天前
autoCAD二次开发 4.正多边形与collection区分
算法·c#·二次开发·autocad二次开发
休息一下接着来1 天前
C++ 固定容量环形队列实现
c++·算法
im_AMBER1 天前
手撕hot100之矩阵!看完这篇就AC~
javascript·数据结构·线性代数·算法·leetcode·矩阵
笨笨饿1 天前
#79_NOP()嵌入式C语言中内联汇编宏的抽象封装模式研究
linux·c语言·网络·驱动开发·算法·硬件工程·个人开发