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;
}
相关推荐
回敲代码的猴子9 分钟前
2月14日打卡
算法
blackicexs1 小时前
第四周第七天
算法
期末考复习中,蓝桥杯都没时间学了1 小时前
力扣刷题19
算法·leetcode·职场和发展
Renhao-Wan1 小时前
Java 算法实践(四):链表核心题型
java·数据结构·算法·链表
zmzb01032 小时前
C++课后习题训练记录Day105
开发语言·c++·算法
好学且牛逼的马3 小时前
【Hot100|25-LeetCode 142. 环形链表 II - 完整解法详解】
算法·leetcode·链表
H Corey3 小时前
数据结构与算法:高效编程的核心
java·开发语言·数据结构·算法
SmartBrain3 小时前
Python 特性(第一部分):知识点讲解(含示例)
开发语言·人工智能·python·算法
01二进制代码漫游日记4 小时前
自定义类型:联合和枚举(一)
c语言·开发语言·学习·算法
小学卷王4 小时前
复试day25
算法