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

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

相关推荐
ZPC82102 小时前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC82102 小时前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
琢磨先生David2 小时前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
颜酱2 小时前
栈的经典应用:从基础到进阶,解决LeetCode高频栈类问题
javascript·后端·算法
多恩Stone2 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
生信大杂烩2 小时前
癌症中的“细胞邻域“:解码肿瘤微环境的空间密码 ——Nature Cancer 综述解读
人工智能·算法
蜡笔小马3 小时前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
m0_531237173 小时前
C语言-数组练习进阶
c语言·开发语言·算法
qq_454245033 小时前
基于组件与行为的树状节点系统
数据结构·c#
超级大福宝3 小时前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode