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

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

相关推荐
孤飞2 小时前
zero2Agent:面向大厂面试的 Agent 工程教程,从概念到生产的完整学习路线
算法
技术专家4 小时前
Stable Diffusion系列的详细讨论 / Detailed Discussion of the Stable Diffusion Series
人工智能·python·算法·推荐算法·1024程序员节
csdn_aspnet4 小时前
C# (QuickSort using Random Pivoting)使用随机枢轴的快速排序
数据结构·算法·c#·排序算法
鹿角片ljp4 小时前
最长回文子串(LeetCode 5)详解
算法·leetcode·职场和发展
广师大-Wzx5 小时前
一篇文章看懂MySQL数据库(下)
java·开发语言·数据结构·数据库·windows·python·mysql
paeamecium6 小时前
【PAT甲级真题】- Cars on Campus (30)
数据结构·c++·算法·pat考试·pat
chh5637 小时前
C++--模版初阶
c语言·开发语言·c++·学习·算法
RTC老炮7 小时前
带宽估计算法(gcc++)架构设计及优化
网络·算法·webrtc
dsyyyyy11017 小时前
计数孤岛(DFS和BFS解决)
算法·深度优先·宽度优先
会编程的土豆8 小时前
01背包与完全背包详解
开发语言·数据结构·c++·算法