[蓝桥杯 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;
}
相关推荐
CQU_JIAKE18 小时前
10.3【A】
深度优先
言乐619 小时前
Python区分广度优先深度优先宽度优先的区别
python·算法·深度优先·广度优先·宽度优先
Dream it possible!1 天前
蓝桥杯_翻转_C++
c++·算法·蓝桥杯
RobinDevNotes2 天前
大模型3D并行训练怎么配才不浪费算力
网络·人工智能·深度学习·深度优先
一条大祥脚2 天前
26 ICPC上海 交互|二分|重心|构造|二分图|贪心|SOSDP|三进制枚举|线性基|字典序贪心|DFS|分块|单侧递归线段树
算法·深度优先·交互·分块·icpc上海站·单侧递归线段树
CQU_JIAKE5 天前
9.29【A】
算法·深度优先
longlongzihan6 天前
LeetCode 17电话号码的字母组合:回溯算法(DFS)详解
c++·算法·leetcode·深度优先
Because_of_Her16 天前
dfs-洪水填充技巧
笔记·算法·深度优先·洪水填充
鑫 源6 天前
VS2019 for mac里用c#开发Mac OS应用 避坑 和 源码
职场和发展·蓝桥杯
Coder-magician7 天前
《代码随想录》刷题打卡day44:图论-part02
算法·深度优先·图论