蓝桥杯 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;
	
}
相关推荐
沙威玛_LHE3 小时前
树和二叉树
数据结构·算法
py有趣5 小时前
LeetCode算法学习之两数之和 II - 输入有序数组
学习·算法·leetcode
夏鹏今天学习了吗5 小时前
【LeetCode热题100(62/100)】搜索二维矩阵
算法·leetcode·矩阵
吃着火锅x唱着歌7 小时前
LeetCode 1128.等价多米诺骨牌对的数量
算法·leetcode·职场和发展
十八岁讨厌编程7 小时前
【算法训练营 · 补充】LeetCode Hot100(中)
算法·leetcode
橘颂TA7 小时前
【剑斩OFFER】算法的暴力美学——最小覆盖字串
算法·c/c++·就业
wearegogog1237 小时前
基于混合蛙跳算法和漏桶算法的无线传感器网络拥塞控制与分簇新方法
网络·算法
程序员龙一8 小时前
C++之static_cast关键字
开发语言·c++·static_cast
奶茶树8 小时前
【C++/STL】map和multimap的使用
开发语言·c++·stl
Tiandaren8 小时前
大模型应用03 || 函数调用 Function Calling || 概念、思想、流程
人工智能·算法·microsoft·数据分析