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;
}
相关推荐
卷福同学1 小时前
【AI编程】AI+高德MCP不到10分钟搞定上海三日游
人工智能·算法·程序员
mit6.8241 小时前
[Leetcode] 预处理 | 多叉树bfs | 格雷编码 | static_cast | 矩阵对角线
算法
皮卡蛋炒饭.1 小时前
数据结构—排序
数据结构·算法·排序算法
??tobenewyorker2 小时前
力扣打卡第23天 二叉搜索树中的众数
数据结构·算法·leetcode
贝塔西塔3 小时前
一文读懂动态规划:多种经典问题和思路
算法·leetcode·动态规划
众链网络3 小时前
AI进化论08:机器学习的崛起——数据和算法的“二人转”,AI“闷声发大财”
人工智能·算法·机器学习
3 小时前
Unity开发中常用的洗牌算法
java·算法·unity·游戏引擎·游戏开发
飒飒真编程5 小时前
C++类模板继承部分知识及测试代码
开发语言·c++·算法
GeminiGlory5 小时前
算法练习6-大数乘法(高精度乘法)
算法
熬了夜的程序员5 小时前
【华为机试】HJ61 放苹果
算法·华为·面试·golang