返回题解分享
讨论 / 题解分享/ 帖子详情

飞机降落(编程题) - 题解

#include <iostream>
using namespace std;
const int N = 15;
int t, n, num, idx;
int T[N], D[N], L[N],q[N];
bool st[N];
void dfs(int x)
{
	if (x > n)
	{
		
		for (int i = 1; i <= n; i ++ )
		{
			if (i == 1) num = T[q[i]] + L[q[i]];
			else
			{
				
				if (num > T[q[i]] + D[q[i]]) return ;
				num += L[q[i]]; 
			}
		}
		idx ++ ;
		return ;
	}
	
	for (int i = 1; i <= n; i ++ )
	{
		if (!st[i])
		{		 
			q[x] = i;
			st[i] = true;			
			dfs(x + 1);
			st[i] = false;
		}
	}
	return ;
}
int main()
{
	cin >> t;
	while (t -- )
	{
		idx = 0;
		num = 0;
		cin >> n;
		for (int i = 1; i <= n; i ++ ) cin >> T[i] >> D[i] >> L[i];
		dfs(1);
		
		if (idx >= 1) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}
0 回复 0 转发 0 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!