[蓝桥杯 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;
}
相关推荐
故事和你9120 小时前
洛谷-算法2-2-常见优化技巧3
开发语言·数据结构·c++·算法·深度优先·动态规划·图论
踩坑记录20 小时前
leetcode hot100 416. 分割等和子集 medium 动态规划 01背包 DFS深度优先搜索
leetcode·深度优先·动态规划
小张的博客之旅21 小时前
2026年第十七届蓝桥杯网络安全赛项WriteUp
安全·web安全·蓝桥杯
6Hzlia1 天前
【Hot 100 刷题计划】 LeetCode 199. 二叉树的右视图 | C++ DFS 逆序遍历
c++·leetcode·深度优先
木井巳2 天前
【递归算法】解数独
java·算法·leetcode·决策树·深度优先·剪枝
EnCi Zheng2 天前
S10-蓝桥杯 17822 乐乐的积木塔
职场和发展·蓝桥杯
The Chosen One9852 天前
算法题目分享(二分算法)
算法·职场和发展·蓝桥杯
酉鬼女又兒2 天前
Leetcode 26.删除有序数组中的重复项 双指针巧解有序数组去重:从快慢指针到原地修改算法的精髓
java·数据结构·算法·leetcode·职场和发展·蓝桥杯·排序算法
贾斯汀玛尔斯2 天前
每天学一个算法--拓扑排序(Topological Sort)
算法·深度优先
旖-旎3 天前
深搜(二叉树的所有路径)(6)
c++·算法·leetcode·深度优先·递归