即将到来的新生赛

思路:数据很小,直接dfs暴力就能过。
按右端点从小到大排序,以便保证当前这个点的r>=上一个选的点的l的同时,也大于之前选的所有点.
path数组存储选不选当前点。
或者也可以,二进制枚举,把每个任务选不选看成一个状态,最多有(1<<20)-1种状态

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N=110;
struct Ac
{
	int l, r, val;
	bool operator < (const Ac &t) const
	{
		return r!=t.r?r<t.r:l<t.l;
	}
};
void dfs(int u);

int T;
int m;
int res;
int path[N];
Ac news[N];

signed main()
{
	cin>>T;
	
	while(T--)
	{
		scanf("%d", &m);
		for(int i=0;i<m;i++) scanf("%d%d%d", &news[i].l, &news[i].r, &news[i].val);
		
		sort(news, news+m);
		
		res=0;
		memset(path, 0, sizeof path);
		dfs(0);
		
		cout<<res<<endl;
	}
}

void dfs(int u)
{
	if(u==m)
	{
		int cnt=0, f=-1;//f存储上一个选的点的下标是哪个
		for(int i=0;i<m;i++)
			if(path[i]==1)
			{
				if(f==-1) cnt+=news[i].val, f=i;
				else if(news[i].l>=news[f].r) cnt+=news[i].val, f=i;
			}
		res=max(res, cnt);
		
		return;
	}
	
	path[u]=1;//选
	dfs(u+1);
	
	path[u]=2;//不选
	dfs(u+1); 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值