Greedy Pie Eaters(区间DP)

题目描述
Farmer John has M cows, conveniently labeled 1…M, who enjoy the occasional change of pace from eating grass. As a treat for the cows, Farmer John has baked N pies (1≤N≤300), labeled 1…N. Cow i enjoys pies with labels in the range [li,ri] (from li to ri inclusive), and no two cows enjoy the exact same range of pies. Cow i also has a weight, wi, which is an integer in the range 1…106.
Farmer John may choose a sequence of cows c1,c2,…,cK, after which the selected cows will take turns eating in that order. Unfortunately, the cows don’t know how to share! When it is cow ci’s turn to eat, she will consume all of the pies that she enjoys — that is, all remaining pies in the interval [lci,rci]. Farmer John would like to avoid the awkward situation occurring when it is a cows turn to eat but all of the pies she enjoys have already been consumed. Therefore, he wants you to compute the largest possible total weight (wc1+wc2+…+wcK) of a sequence c1,c2,…,cK for which each cow in the sequence eats at least one pie.

SCORING:
Test cases 2-5 satisfy N≤50 and M≤20.
Test cases 6-9 satisfy N≤50.

输入
The first line contains two integers N and M (1≤M≤N(N+1)/2).
The next M lines each describe a cow in terms of the integers wi,li, and ri.

输出
Print the maximum possible total weight of a valid sequence.

样例输入
2 2
100 1 2
100 1 1

样例输出
200

提示
In this example, if cow 1 eats first, then there will be nothing left for cow 2 to eat. However, if cow 2 eats first, then cow 1 will be satisfied by eating the second pie only.

思路
区间DP找区间的最大值

代码实现

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值