蓝桥杯 2023省B 飞机降落 dfs

传送门 P9241 [蓝桥杯 2023 省 B] 飞机降落 - 洛谷

n<=10,考虑dfs,只有当 当前飞机的到达时刻+盘旋时间 <= 上一个飞机降落的时刻 时,当前飞机才能降落

cpp 复制代码
const int N = 1e3 + 10;


int n;
struct Node
{
	LL t,d,l;
}a[N];

bool st[N];

bool dfs(int u,LL last)
{
	if (u > n) return true;
	

	for (int i = 1;i <= n;i ++)
	{
		
		if (!st[i] && a[i].t + a[i].d >= last)
		{
			st[i] = true;
			if (dfs(u + 1,max(a[i].t,last) + a[i].l)) return true;
			st[i] = false;
		}
	}
	
	
	return false;
}

void solve()
{
	cin >> n;
	memset(st,0,sizeof st);
	
	for (int i = 1;i <= n;i ++)
	{
		int t,d,l;cin >> t >> d >> l;
		a[i] = {t,d,l};
	}		
	
	if (dfs(1,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	
}
相关推荐
CSCN新手听安25 分钟前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C1 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical612 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++
YXXY3132 小时前
模拟算法的介绍
算法
Hical612 小时前
实测:C++20 协程 vs Go Gin vs Rust Actix,谁的 Web 性能更强?
c++
happymaker06263 小时前
简单LRU的实现(基于LinkedHashMap)
算法·leetcode·lru
草莓熊Lotso3 小时前
《告别 “会用不会讲”:C++ string 底层原理拆解 + 手撕实现,面试 / 开发都适用》
开发语言·c++·面试
会编程的土豆3 小时前
【数据结构与算法】空间复杂度从入门到面试:不仅会算,还要会解释
数据结构·c++·算法·面试·职场和发展
普通网友3 小时前
《算法面试必刷:15 个高频 LeetCode 题(附代码)》
算法·leetcode·面试
_深海凉_3 小时前
LeetCode热题100-搜索二维矩阵
算法·leetcode·矩阵