[蓝桥杯 2023 省 B] 飞机降落(暴搜DFS+贪心)

总结:为什么你看到题想不出来怎么写呢,我想不到这道题还会用到dfs的思想,顶多能知道可能会有贪心,还是得多做题。

这道题让我想起来导弹拦截和借教室,记得有空做做!!不要研究难题,把基本算法研究透了!!!别死磕,要灵活!

DFS代码:

cpp 复制代码
//要用DFS 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

int tt;
int n;
struct node{
	int t;
	int d;
	int l;
};
node a[15];

bool st[15];

bool dfs(int u,int last){
	if(u == n) return true;//如果搜索过所有点
	for(int i=0;i<n;i++){
		int t=a[i].t,d=a[i].d,l=a[i].l;
		if(!st[i] && t+d >= last)//如果没有被搜索过,并且 这一次a[i]的开头在上一次结束的时间后面
		{
			st[i] = true;//能被搜索
			if(dfs(u+1,max(last,t)+l))
				return true;
			st[i] = false;//恢复现场	
		} 
	} 
	return false; 
}
int main()
{
	scanf("%d",&tt);
	while(tt--){

		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&a[i].t,&a[i].d,&a[i].l);
			//或者scanf("%d%d%d",&t,&d,&l);
			//    p[i] = {t,d,l}; 
		}
		memset(st,false,sizeof(st));
		if(dfs(0,0)) puts("YES");
		else puts("NO");
	}
	return 0;
}
相关推荐
青少儿编程课堂11 小时前
2026蓝桥杯青少组:校园飞鸟穿越赛解析
蓝桥杯·scratch·少儿编程·图形化编程·蓝桥杯青少组
INGNIGHT1 天前
815 · 课程表IV(dfs)
算法·深度优先
aqiu1111112 天前
蓝桥杯真题复盘:Fibonacci 数列与黄金分割(C++ 算法详解)
c++·算法·蓝桥杯
aqiu1111113 天前
题目总结:[P8752 [蓝桥杯 2021 省 B2] 特殊年份]
蓝桥杯
青少儿编程课堂3 天前
2026蓝桥杯青少组:校园防疫大作战解析
蓝桥杯·scratch·少儿编程·图形化编程·蓝桥杯青少组
垆边人似月.4 天前
删边使每个连通块权值和为 target
算法·深度优先·图论
MoRanzhi12035 天前
106.正则问题(分治)
python·算法·正则表达式·蓝桥杯·递归·分治算法·字符串处理
MoRanzhi12035 天前
122.四平方和(暴力枚举)
python·数学·算法·蓝桥杯·完全平方数·暴力枚举·四平方和定理
垆边人似月.6 天前
华为题:矩阵中的最长递增路径
算法·深度优先
无忧.芙桃7 天前
图的精髓:邻接矩阵与遍历全解析
c++·算法·面试·深度优先·广度优先