[蓝桥杯 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;
}
相关推荐
独自破碎E5 天前
【DFS】BISHI76 迷宫寻路
算法·深度优先
代码无bug抓狂人5 天前
C语言之单词方阵——深搜(很好的深搜例题)
c语言·开发语言·算法·深度优先
码农幻想梦5 天前
3472. 八皇后(北京大学考研机试题目)
考研·算法·深度优先
重生之后端学习5 天前
74. 搜索二维矩阵
开发语言·数据结构·算法·职场和发展·深度优先
觅特科技-互站5 天前
实测:接入陌讯Skills后Copilot任务完成率↑63%、调试耗时↓90%
线性回归·深度优先·copilot
重生之后端学习5 天前
35. 搜索插入位置
java·数据结构·算法·leetcode·职场和发展·深度优先
zaiyang遇见5 天前
[GESP202509 六级] 货物运输
深度优先·贪心·树的遍历·gesp六级·树的存储
筱昕~呀5 天前
冲刺蓝桥杯-DFS板块(第二天)
算法·蓝桥杯·深度优先
每天要多喝水5 天前
图论Day39:孤岛题目
算法·深度优先·图论
独自破碎E5 天前
【DFS】BISHI77数水坑
算法·深度优先