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

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

#include <bits/stdc++.h>
using namespace std;

const int N = 20;
struct plane
{
    int t, d, l;
} p[N];
int T, n;
int vis[N];
bool dfs(int x, int cur) // cur为下降时间
{
    if (x > n)
        return 1;
    for (int i = 1; i <= n; i++)
    {
        if (vis[i] || cur > (p[i].t + p[i].d))
            continue;
        vis[i] = 1;
        if (dfs(x + 1, max(cur, p[i].t) + p[i].l))
        {
            vis[i] = 0;
            return 1;
        }
        vis[i] = 0;
    }
    return 0;
}
int main()
{
    cin >> T;
    while (T--)
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> p[i].t >> p[i].d >> p[i].l;
        }
        if (dfs(1, 0))
        {
            puts("YES");
        }
        else
            puts("NO");
    }
    return 0;
}
0 回复 0 转发 0 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!