[蓝桥杯 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;
}
相关推荐
计算机小白一个1 小时前
蓝桥杯 Java B 组之背包问题(01背包、完全背包)
java·职场和发展·蓝桥杯
KuunNNn1 小时前
蓝桥杯试题:小明的彩灯(差分 && 前缀和)
蓝桥杯
SuperW4 小时前
蓝桥杯——adc的测量
蓝桥杯
计算机小白一个12 小时前
蓝桥杯 Java B 组之设计 LRU 缓存
java·算法·蓝桥杯
欧了11114 小时前
洛谷P9240 [蓝桥杯 2023 省 B] 冶炼金属
职场和发展·蓝桥杯·洛谷·蓝桥杯大学b组c语言
一只码代码的章鱼16 小时前
数据结构与算法-搜索-剪枝
算法·深度优先·剪枝
计算机小白一个19 小时前
蓝桥杯 Java B 组之背包问题、最长递增子序列(LIS)
java·数据结构·蓝桥杯
SuperW19 小时前
蓝桥杯——lcd显示
职场和发展·蓝桥杯
gyeolhada1 天前
2025蓝桥杯JAVA编程题练习Day5
java·数据结构·算法·蓝桥杯
_小苔藓_1 天前
初探动态规划--记忆化搜索
深度优先·动态规划·代理模式