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;
}
相关推荐
墨染点香21 小时前
LeetCode 刷题【128. 最长连续序列】
算法·leetcode·职场和发展
被AI抢饭碗的人21 小时前
算法题(240):最大食物链计数
算法
熬了夜的程序员1 天前
【LeetCode】82. 删除排序链表中的重复元素 II
数据结构·算法·leetcode·链表·职场和发展·矩阵·深度优先
欧克小奥1 天前
Floyd判圈算法(Floyd Cycle Detection Algorithm)
算法·floyd
熬了夜的程序员1 天前
【LeetCode】83. 删除排序链表中的重复元素
算法·leetcode·链表
胖咕噜的稞达鸭1 天前
AVL树手撕,超详细图文详解
c语言·开发语言·数据结构·c++·算法·visual studio
YSRM1 天前
Leetcode+Java+图论II
java·leetcode·图论
熊猫钓鱼>_>1 天前
Rust语言特性深度解析:所有权、生命周期与模式匹配之我见
算法·rust·软件开发·函数·模式匹配·异步编程·质量工具
芒果量化1 天前
Optuna - 自动调参利器&python实例
开发语言·python·算法·机器学习
麦麦大数据1 天前
D025 摩托车推荐价格预测可视化系统|推荐算法|机器学习|预测算法|用户画像与数据分析
mysql·算法·机器学习·django·vue·推荐算法·价格预测