[蓝桥杯 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;
}
相关推荐
墨辰JC1 天前
C语言可变参数讲解:stdarg.h应用
c语言·开发语言·蓝桥杯·内存·蓝桥杯嵌入式
Boilermaker19922 天前
[算法基础] FooldFill(DFS、BFS)
算法·深度优先·宽度优先
平生不喜凡桃李2 天前
Leetcode-240 :搜索二维矩阵
leetcode·矩阵·深度优先
_OP_CHEN2 天前
【算法基础篇】(四十一)数论之约数问题终极攻略:从求单个约数到批量统计
c++·算法·蓝桥杯·数论·约数·算法竞赛·acm/icpc
小谢啥都不会3 天前
蓝桥杯(三)——闫氏DP
python·蓝桥杯
WW_千谷山4_sch3 天前
洛谷P1120&UVA307 [CERC 1995] 小木棍
c++·算法·深度优先
墨辰JC3 天前
STM32串口通信DMA接收 + 空闲中断IDLE详解
stm32·单片机·嵌入式硬件·蓝桥杯·idle·dma
cpp_25013 天前
P8597 [蓝桥杯 2013 省 B] 翻硬币
数据结构·c++·算法·蓝桥杯·题解
WW_千谷山4_sch3 天前
洛谷P8653:[模板] [蓝桥杯 2017 国 C] 分考场(染色最小色数)
c++·算法·蓝桥杯·深度优先
Swift社区4 天前
LeetCode 464 我能赢吗
算法·leetcode·深度优先