题海拾贝: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;
}

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

相关推荐
Darkwanderor8 小时前
什么数据量适合用什么算法
c++·算法
zc.ovo9 小时前
河北师范大学2026校赛题解(A,E,I)
c++·算法
py有趣9 小时前
力扣热门100题之环形链表
算法·leetcode·链表
py有趣9 小时前
力扣热门100题之回文链表
算法·leetcode·链表
Kk.08029 小时前
数据结构|链表 刷题
数据结构·链表
月落归舟10 小时前
帮你从算法的角度来认识二叉树---(二)
算法·二叉树
清华都得不到的好学生11 小时前
数据结构->1.稀疏数组,2.数组队列(没有取模),3.环形队列
java·开发语言·数据结构
SilentSlot11 小时前
【数据结构】Hash
数据结构·算法·哈希算法
是娇娇公主~12 小时前
Lambda表达式详解
数据结构·c++