?????????Hello大家好!很高興我們又見面啦!給生活添點passion,開始今天的編程之路!
我的博客:<但凡.
我的專欄:《編程之路》、《數據結構與算法之美》、《題海拾貝》
歡迎點贊,關注!
1、題目?
2、題解?
#include<iostream>
#include<cstring>
using namespace std;
const int N = 15;
int T, n;
int t[N], d[N], l[N];
bool st[N];
bool dfs(int pos, int end)//第幾加以及結束時間
{if (pos > n) return true;for (int i = 1;i <= n;i++){if (st[i] == true) continue;if (end > t[i] + d[i]) continue;int newend = max(t[i], end) + l[i];st[i] = true;if (dfs(pos + 1, newend)) return true;st[i] = false;}return false;
}
int main()
{cin >> T;while (T--){memset(st, 0, sizeof st);cin >> n;for (int i = 1;i <= n;i++){cin >> t[i]>>d[i]>>l[i];}if (dfs(1, 0)) cout << "YES" << endl;else cout << "NO" << endl;}return 0;
}
? ? ? ? 好了,今天的內容就分享到這,我們下期再見!
?