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

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

相关推荐
无敌憨憨大王几秒前
并查集(图论)
数据结构·算法·图论
xiaoye-duck1 分钟前
《算法题讲解指南:动态规划算法--路径问题》--7.礼物的最大价值,8.下降路径最小和
c++·算法·动态规划
光影少年5 分钟前
react的diff算法和vue的diff算法区别
vue.js·算法·react.js
Queenie_Charlie8 分钟前
二分匹配
c++·算法·二分匹配
历程里程碑8 分钟前
链表--排序链表
大数据·数据结构·算法·elasticsearch·链表·搜索引擎·排序算法
念越9 分钟前
第十七届蓝桥杯软件测试模拟赛1期题目及解析
蓝桥杯·测试用例·测试
IT猿手10 分钟前
基于动态三维环境下的Q-Learning算法无人机自主避障路径规划研究,MATLAB代码
算法·matlab·无人机·动态路径规划·多无人机动态避障路径规划
美式请加冰13 分钟前
栈的介绍和使用(算法)
数据结构·算法·leetcode
不染尘.14 分钟前
排序算法详解2
数据结构·c++·算法·排序算法
cm65432015 分钟前
C++代码切片分析
开发语言·c++·算法