蓝桥杯 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;
	
}
相关推荐
科研小白_19 小时前
基于遗传算法优化BP神经网络(GA-BP)的数据时序预测
人工智能·算法·回归
Terry Cao 漕河泾19 小时前
基于dtw算法的动作、动态识别
算法
Larry_Yanan21 小时前
QML学习笔记(四十)QML的ApplicationWindow和StackView
c++·笔记·qt·学习·ui
Miraitowa_cheems1 天前
LeetCode算法日记 - Day 73: 最小路径和、地下城游戏
数据结构·算法·leetcode·职场和发展·深度优先·动态规划·推荐算法
野蛮人6号1 天前
力扣热题100道之560和位K的子数组
数据结构·算法·leetcode
Swift社区1 天前
LeetCode 400 - 第 N 位数字
算法·leetcode·职场和发展
fengfuyao9851 天前
BCH码编译码仿真与误码率性能分析
算法
Kratzdisteln1 天前
【C语言】Dev-C++如何编译C语言程序?从安装到运行一步到位
c语言·c++
小白不想白a1 天前
每日手撕算法--哈希映射/链表存储数求和
数据结构·算法
剪一朵云爱着1 天前
力扣2080. 区间内查询数字的频率
算法·leetcode