题面

题解

第一眼:线段树优化连边的裸题

刚准备打,突然发现:

\(1 \leq S_i \leq T_i \leq 10^8\)

这™用个鬼的线段树啊

经过一番寻找,在网上找到了一篇论文

大家可以去看一下,这里只提示大家用类似匈牙利算法贪心

这里还有代码

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x)) inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-' && (!isdigit(ch))) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
} const int maxn(5010);
struct node { int l, r, val; } p[maxn];
int n, val[maxn], match[maxn];
long long ans;
inline bool cmp_1(const node &a, const node &b) { return a.l < b.l; }
inline bool cmp_2(const node &a, const node &b) { return a.val > b.val; } int hungary(int x, int y)
{
if(val[y] > p[x].r) return 0;
if(!match[y]) return (match[y] = x, 1);
if(p[match[y]].r < p[x].r) return hungary(x, y + 1);
else if(hungary(match[y], y + 1)) return (match[y] = x, 1);
return 0;
} int main()
{
n = read();
for(RG int i = 1; i <= n; i++) p[i] = (node) {read(), read(), read()};
std::sort(p + 1, p + n + 1, cmp_1);
for(RG int i = 1; i <= n; i++) val[i] = std::max(val[i - 1] + 1, p[i].l);
for(RG int i = 1, j = 1; i <= n; i++)
{
while(j < n && val[j] < p[i].l) ++j;
p[i].l = j;
}
std::sort(p + 1, p + n + 1, cmp_2);
for(RG int i = 1; i <= n; i++)
if(hungary(i, p[i].l)) ans += p[i].val;
printf("%lld\n", ans);
return 0;
}

BZOJ2034 【2009国家集训队】最大收益的更多相关文章

  1. BZOJ2034 [2009国家集训队]最大收益

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  2. 【BZOJ2034】[2009国家集训队]最大收益 贪心优化最优匹配

    [BZOJ2034][2009国家集训队]最大收益 Description 给出N件单位时间任务,对于第i件任务,如果要完成该任务,需要占用[Si, Ti]间的某个时刻,且完成后会有Vi的收益.求最大 ...

  3. BZOJ 2034: [2009国家集训队]最大收益 [贪心优化 Hungary]

    2034: [2009国家集训队]最大收益 题意:\(n \le 5000\)个区间\(l,r\le 10^8\),每个区间可以选一个点得到val[i]的价值,每个点最多选1次,求最大价值 线段树优化 ...

  4. 【bzoj2034】 2009国家集训队—最大收益

    http://www.lydsy.com/JudgeOnline/problem.php?id=2034 (题目链接) 题意 n个任务,每个任务只需要一个时刻就可以完成,完成后获得${W_i}$的收益 ...

  5. Bzoj2034 2009国家集训队试题 最大收益 贪心+各种优化+二分图

    这个题真的是太神了... 从一開始枚举到最后n方的转化,各种优化基本都用到了极致.... FQW的题解写了好多,个人感觉我全然没有在这里废话的必要了 直接看这里 各种方法真的是应有尽有 大概说下 首先 ...

  6. BZOJ.2034.[2009国家集训队]最大收益(二分图匹配 贪心)

    题目链接 双倍经验:BZOJ.4276.[ONTAK2015]Bajtman i Okrągły Robin(然而是个权限题.区间略有不同) \(Description\) 有\(n\)个任务,完成一 ...

  7. BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割

    BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作 ...

  8. BZOJ 2039: [2009国家集训队]employ人员雇佣

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1369  Solved: 667[Submit ...

  9. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) [莫队算法]【学习笔记】

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7687  Solved: 3516[Subm ...

  10. BZOJ 2038: [2009国家集训队]小Z的袜子(hose)

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7676  Solved: 3509[Subm ...

随机推荐

  1. [翻译] DKTagCloudView - 标签云View

    DKTagCloudView 效果(支持点击view触发事件): Overview DKTagCloudView is a tag clouds view on iOS. It can generat ...

  2. C++ 课堂作业1.0

    c++第一次课堂作业点这里 题目要求:输入半径,计算圆的面积,在调用外部函数,无需使用类.

  3. 手动安装 pygame

    在windows下 用pip 安装pygame,老是失败,下载了 wheel文件,用pip安装还是不行,查了一下资料,可以手动安装: 1.在 http://www.lfd.uci.edu/~gohlk ...

  4. 【Java 笔记】 java 格式化输出

    public static void main(String[] args) { /** * 格式化形式 * %[argument_index$][flags][width][.precision]c ...

  5. No Spring WebApplicationInitializer types detected on classpath异常的解决

    1.问题描述,当配置成 时,通过地址栏访问默认路径的index.jsp报404错误,如果手动在浏览器输入“http://localhost:8080/index.jsp”,则出现源码文件,然后观察ec ...

  6. sed 以及 awk用法

    sed 格式 sed[options] "script" FILE.... 选项: -n:静默模式,不输出模式空间内的内容:默认打印空间模式的内容 -r:扩展的正则表达式 -f 文 ...

  7. linux下10款markdown软件

    原文:https://linux.cn/article-7623-1.html 在这篇文章中,我们会点评一些可以在 Linux 上安装使用的最好的 Markdown 编辑器. 你可以在 Linux 平 ...

  8. Jenkins启动和停止服务

    1.怎么启动Jenkins? step1:进入到Jenkins的war包所在的目录. 如果是win7及以上版本,直接打开Jenkins的war包所在的目录,在地址栏敲cmd,回车. 上述结果和进入cm ...

  9. 统计Azure存储的HBase各表数据量

    场景:HBase存储在Azure上,现在通过访问Azure Storage的接口,获取HBase中各个表的数据量. 注意: 1.Azure存储,默认的副本数为2,即共存3份,但只收1份的费用,取到的s ...

  10. 企业案例 【故障修复】mysql主从故障解决过程

    由于配置有zabbix监控,某日收到zabbix监控主从报警,,查看mysql状态, showslave status \G; slave复制状态有误,SLAVE_SQL_RUNNING为NO, 接着 ...