P9241 [蓝桥杯 2023 省 B] 飞机降落

1.10分代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long int
int n;
int a[20], t[20], d[20], l[20];
int dfs(int x, int time) {
	if (x >= n)
		return 1;
	for (int i = 1; i <= n; i++) {
		if (!a[i] && t[i] + d[i] >= time) {
			a[i] = 1;
			int u = max(time, t[i])+l[i];
			if (dfs(x + 1, u))
				return 1;
			a[i] = 0;//回溯
		}
	}
	return 0;
}
void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> d[i] >> l[i];
	}
	memset(a, 0, sizeof(a));
	if (dfs(1, -1))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
		
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	cin >> t;
	while (t--)
	solve();
    return 0;
}
相关推荐
happymaker062615 分钟前
简单LRU的实现(基于LinkedHashMap)
算法·leetcode·lru
会编程的土豆26 分钟前
【数据结构与算法】空间复杂度从入门到面试:不仅会算,还要会解释
数据结构·c++·算法·面试·职场和发展
普通网友28 分钟前
《算法面试必刷:15 个高频 LeetCode 题(附代码)》
算法·leetcode·面试
_深海凉_30 分钟前
LeetCode热题100-搜索二维矩阵
算法·leetcode·矩阵
张槊哲41 分钟前
C++ 进阶指南:如何丝滑地理解与实践多线程与多进程
开发语言·c++·算法
代码中介商1 小时前
C语言链表完全指南:从单节点到链表管理
c语言·算法·链表
小小de风呀2 小时前
de风——【从零开始学C++】(四):类和对象(下)
开发语言·c++·算法
aqiu1111112 小时前
[特殊字符]【算法日记 14】数论入门神题:最大公约数与最小公倍数的“乘积守恒定律”
算法
保卫大狮兄2 小时前
一文讲清:仓库管理最核心的10个公式
人工智能·算法·仓库管理
翻身的咸鱼ing3 小时前
常用代码知识
算法·深度优先·哈希算法