0分
查看原帖
0分
551630
Lemon_zqp楼主2024/7/28 13:03

rt,样例正常,怀疑数据有误?

#include<bits/stdc++.h>
#define int long long
const int mod = 1e9 + 7;
using namespace std;

int s[105], d[105], l[105], e[105], n;
bool vis[105], ok;

void dfs(int x, int t){
	if(ok == true){
		return;
	}
	if(x > n){
		ok = true;
		return;
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]){
			if(t > e[i]){
				return;
			}
			vis[i] = true;
			if(t < s[i]){
				dfs(x + 1, s[i] + l[i]);
			}
			else{
				dfs(x + 1, t + l[i]);
			}
			vis[i] = false;
		}
	}
}

signed main()
{
	int T;
	cin >> T;
	while(T--){
		cin >> n;
		for(int i = 1; i <= n; i++){
			cin >> s[i] >> d[i] >> l[i];
			e[i] = s[i] + d[i];
		}
		memset(vis, 0, sizeof(vis));
		ok = false;
		dfs(1, 0);
		if(ok){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}
2024/7/28 13:03
加载中...