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

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

相关推荐
NuyoahC16 分钟前
笔试——Day23
c++·算法·模拟
恣艺1 小时前
LeetCode 68:文本左右对齐
算法·leetcode·c#
Alfred king1 小时前
Leetcode 四数之和
算法·leetcode·职场和发展·数组·排序·双指针
Jay Kay1 小时前
跳跃表可视化深度解析:动态演示数据结构核心原理
数据结构·数据库
OKkankan2 小时前
string类的模拟实现
开发语言·数据结构·c++·算法
虾饺爱下棋3 小时前
FCN语义分割算法原理与实战
人工智能·python·神经网络·算法
云手机掌柜4 小时前
从0到500账号管理:亚矩阵云手机多开组队与虚拟定位实战指南
数据结构·线性代数·网络安全·容器·智能手机·矩阵·云计算
Eloudy7 小时前
简明量子态密度矩阵理论知识点总结
算法·量子力学
点云SLAM7 小时前
Eigen 中矩阵的拼接(Concatenation)与 分块(Block Access)操作使用详解和示例演示
人工智能·线性代数·算法·矩阵·eigen数学工具库·矩阵分块操作·矩阵拼接操作
没书读了7 小时前
考研复习-数据结构-第八章-排序
数据结构