[蓝桥杯 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;
}
相关推荐
浅念-7 小时前
LeetCode 记忆化搜索 刷题总结
数据结构·算法·leetcode·职场和发展·深度优先·dfs
枫叶林FYL9 小时前
Tree-of-Thought (ToT) 架构:BFS/DFS搜索策略、价值函数评估、剪枝机制实现
深度优先·剪枝·宽度优先
_日拱一卒19 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
迈巴赫车主1 天前
蓝桥杯21247弹跳鞋java
java·开发语言·数据结构·算法·职场和发展·蓝桥杯
Trouvaille ~2 天前
【优选算法篇】深入浅出链表算法:交换、重排与合并的终极策略
c++·算法·链表·面试·蓝桥杯·笔试·后端开发
Dlrb12112 天前
数据结构-树与二叉树
数据结构·二叉树·深度优先··广度优先·层序遍历
山峰哥2 天前
索引策略与SQL优化:从Explain对比到生产调优的完整方法论
android·java·数据库·sql·性能优化·深度优先
码之气三段.3 天前
牛客周赛 Round 145-E(写了200行的史山)
算法·深度优先
如竟没有火炬3 天前
有序矩阵中第K小的元素
数据结构·线性代数·算法·leetcode·矩阵·深度优先
浅念-3 天前
LeetCode刷题专题:FloodFill泛滥填充算法剖析
数据结构·算法·leetcode·职场和发展·深度优先·宽度优先