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

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

相关推荐
sin_hielo19 小时前
leetcode 1411(递推)
数据结构·算法·leetcode
一起养小猫20 小时前
LeetCode100天Day10-单词规律与同构字符串
java·开发语言·数据结构
颜酱20 小时前
学习卡特兰数:从原理到应用,解决所有递推计数问题
前端·javascript·算法
漫随流水20 小时前
leetcode算法(20.有效的括号)
数据结构·算法·leetcode
如果你想拥有什么先让自己配得上拥有20 小时前
数、自然数、整数、有理数、无理数它们的定义由来和边界划分
算法
Xの哲學21 小时前
Linux SLUB 内存分配器深度剖析: 从设计哲学到实战调试
linux·服务器·网络·算法·边缘计算
tobias.b1 天前
408真题解析-2009-1-数据结构-队列-进出规则-应用
数据结构·考研·408真题
2401_876221341 天前
AtCoder Beginner Contest 439 - D - Kadomatsu Subsequence
c++·算法
小丁努力不焦虑1 天前
算法期末总结题
数据结构·算法
嵌入式进阶行者1 天前
【算法】从数组中选取两个符合一定条件的数的算法与实例:华为OD机考双机位A卷 - 跳房子I
数据结构·c++·算法·链表