[蓝桥杯 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;
}
相关推荐
NEFU_Jyj13 小时前
牛客周赛R166(max型瓶颈最短路,前后缀DP合并)
算法·深度优先
十二1 天前
【洛谷题解】P1115 最大子段和(前缀和 + 维护最小前缀)
数据结构·c++·算法·蓝桥杯
?abc!3 天前
(动态规划+DFS)494. 目标和
算法·深度优先·动态规划
青少儿编程课堂4 天前
2026蓝桥杯青少组:校园飞鸟穿越赛解析
蓝桥杯·scratch·少儿编程·图形化编程·蓝桥杯青少组
INGNIGHT4 天前
815 · 课程表IV(dfs)
算法·深度优先
aqiu1111116 天前
蓝桥杯真题复盘:Fibonacci 数列与黄金分割(C++ 算法详解)
c++·算法·蓝桥杯
aqiu1111116 天前
题目总结:[P8752 [蓝桥杯 2021 省 B2] 特殊年份]
蓝桥杯
青少儿编程课堂6 天前
2026蓝桥杯青少组:校园防疫大作战解析
蓝桥杯·scratch·少儿编程·图形化编程·蓝桥杯青少组
垆边人似月.7 天前
删边使每个连通块权值和为 target
算法·深度优先·图论
MoRanzhi12038 天前
106.正则问题(分治)
python·算法·正则表达式·蓝桥杯·递归·分治算法·字符串处理