蓝桥杯 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;
	
}
相关推荐
老马啸西风7 分钟前
Neo4j GDS-09-neo4j GDS 库中路径搜索算法实现
网络·数据库·算法·云原生·中间件·neo4j·图数据库
mahuifa36 分钟前
(2)VTK C++开发示例 --- 绘制多面锥体
c++·vtk·cmake·3d开发
xiongmaodaxia_z738 分钟前
python每日一练
开发语言·python·算法
zy_destiny1 小时前
【非机动车检测】用YOLOv8实现非机动车及驾驶人佩戴安全帽检测
人工智能·python·算法·yolo·机器学习·安全帽·非机动车
23级二本计科1 小时前
C++ Json-Rpc框架-3项目实现(2)
服务器·开发语言·c++·rpc
rigidwill6662 小时前
LeetCode hot 100—搜索二维矩阵
数据结构·c++·算法·leetcode·矩阵
短尾黑猫2 小时前
[LeetCode 1696] 跳跃游戏 6(Ⅵ)
算法·leetcode
矛取矛求2 小时前
栈与队列习题分享(精写)
c++·算法
袖清暮雨2 小时前
【专题】搜索题型(BFS+DFS)
算法·深度优先·宽度优先