[蓝桥杯 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;
}
相关推荐
山峰哥5 小时前
数据库工程与索引策略实战指南‌
服务器·数据库·sql·oracle·深度优先
Tisfy8 小时前
LeetCode 2685.统计完全连通分量的数量:DFS求每个连通块的边点数
算法·leetcode·深度优先··题解·连通图·全连通分量
青山木10 小时前
Hot 100 --- 二叉树与递归
java·数据结构·算法·leetcode·深度优先
有点。13 小时前
C++深度优先搜索(DFS)的概念(一)
开发语言·c++·深度优先
ysa05103014 小时前
【板子】欧拉序
c++·笔记·算法·深度优先·图论
山峰哥14 小时前
‌Explain实战:打开数据库执行计划的黑盒‌
大数据·服务器·数据库·sql·深度优先·宽度优先
山峰哥1 天前
数据库工程与SQL优化实战指南‌
数据库·sql·oracle·深度优先·宽度优先
奋发向前wcx2 天前
P2590 树的统计 题目解析
数据结构·算法·深度优先
变量未定义~3 天前
单调栈、单调队列(模板)、子矩阵(模板)
数据结构·算法·蓝桥杯
网络与设备以及操作系统学习使用者5 天前
通信的物理与逻辑双维度解析
学习·深度优先