铁铁我爱说实话


私信TA

用户名:dotcpp0727433

访问量:640

签 名:

等  级
排  名 26963
经  验 519
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校 湖北工程学院
专  业

  自我简介:

TA的其他文章


解题思路:

注意事项:

参考代码:

#include<bits/stdc++.h>
#include<vector>
using namespace std;
int flag=0;

class plane
{
	public:
		plane(int a,int b,int c)
		{
			this->t=a;
			this->d=b;
			this->l=c;
		}
		int t;
		int d;
		int l;
		bool state=1;
};
vector<plane>p;
int count=0;
void DFS(vector<plane>p,int x,int t)
{
	for(int i=0; i<p.size(); i++)
	{
		if(flag==1) break;
		if(p[i].state==0) continue;
		if(t<=p[i].t)
		{
			if(x==p.size()-1) flag=1;
			p[i].state=0;
			DFS(p,x+1,p[i].t+p[i].l);
			p[i].state=1;
		}
		else if(t<=p[i].d+p[i].t)
		{
			if(x==p.size()-1) flag=1;
			p[i].state=0;
			DFS(p,x+1,t+p[i].l);
			p[i].state=1;
		}
		else continue;
	}
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		flag=0;
		int n;
		cin>>n;
		for(int i=0; i<n; i++)
		{
			int a,b,c;
			cin>>a>>b>>c;
			p.push_back(plane(a,b,c));
		}
		DFS(p,0,0);
		if(flag==1)
		{
			cout<<"YES"<<endl;
			p.clear();
		}
		else
		{
			cout<<"NO"<<endl;
			p.clear();
		}
	}
	return 0;
}


 

0.0分

4 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区