这个题真的是太神了。。。

从一開始枚举到最后n方的转化,各种优化基本都用到了极致。。。。

FQW的题解写了好多,个人感觉我全然没有在这里废话的必要了

直接看这里

各种方法真的是应有尽有

大概说下

首先能够想到一个KM算法求二分图最大代权匹配的问题对吧

左边是任务右边是时间

可是这个是三次方啊

那我们就按价值排序,这样就不用代权匹配了可是还是三方

可是左边在右边的连线是单调的。。。

所以就能够贪心推断了。。。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define MAX 5010
#define rep(i,j,k) for(int i = j; i <= k; i++) using namespace std; int n, Link[MAX];
long long ans = 0;
int b[MAX]; struct wbysr
{
int Begin, end, value;
} a[MAX]; bool cmp (wbysr a1, wbysr a2)
{
return a1.Begin < a2.Begin || (a1.Begin == a2.Begin && a1.end < a2.end);
} bool cmp2 (wbysr a1, wbysr a2)
{
return a1.value > a2.value;
} bool find (int now, int x)
{
if (b[x] > a[now].end)
return 0;
if (!Link[x])
{
Link[x] = now;
return 1;
}
int j = Link[x];
if (a[now].end > a[j].end)
return find (now,x + 1);
else
{
if (find(j, x + 1))
{
Link[x] = now;
return 1;
}
}
return 0;
} int main()
{
scanf ("%d", &n);
rep (i, 1, n)
scanf ("%d%d%d", &a[i].Begin, &a[i].end, &a[i].value);
sort (a + 1, a + 1 + n, cmp);
int now = 0;
rep (i, 1, n)
{
now = max (now + 1, a[i].Begin);
b[i] = now;
}
sort (a + 1, a + 1 + n, cmp2);
b[n+1] = 0x7fffffff / 3;
rep (i, 1, n)
{
int j;
for (j = 1; j <= n; j++)
if (b[j] >= a[i].Begin && b[j] <= a[i].end)
break;
if (find(i, j))
ans += a[i].value;
}
cout << ans << endl;
return 0;
}

Bzoj2034 2009国家集训队试题 最大收益 贪心+各种优化+二分图的更多相关文章

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

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

  2. BZOJ2034 【2009国家集训队】最大收益

    题面 题解 第一眼:线段树优化连边的裸题 刚准备打,突然发现: \(1 \leq S_i \leq T_i \leq 10^8\) 这™用个鬼的线段树啊 经过一番寻找,在网上找到了一篇论文 大家可以去 ...

  3. BZOJ 2034 【2009国家集训队】 最大收益

    Description 给出\(N\)件单位时间任务,对于第\(i\)件任务,如果要完成该任务,需要占用\([S_i, T_i]\)间的某个时刻,且完成后会有\(V_i\)的收益.求最大收益. 澄清: ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. linux shell 札记

    shell 数组 数组索引: 单个元素索引: ${array[n]} 全部元素:   ${array[*]}  或者  ${array[@]} 部分索引: ${array[2:]} 数组所有元素统一加 ...

  2. java后台开发- NOTE

    2015-1-6: IDEA servlet-api.jar idea从14升级到15后,发现 import javax.servlet.AsyncContext; 找不到,右击工程,open mod ...

  3. WPF 三态按钮(PNG贴图)

    原文 http://blog.csdn.net/power_YQ/article/details/7177183 <Window.Resources> Style x:Key=" ...

  4. rsyslog 配置详解

    格式:: 日志设备(类型).(连接符号)日志级别 日志处理方式(action) 日志设备(可以理解为日志类型): ------------------------ auth –pam产生的日志 aut ...

  5. MySQL加强

    MySQL加强 Default Not null Unique Primary key Zerofill primary key auto_increment primary key auto_inc ...

  6. codechef Chef and The Right Triangles 题解

    Chef and The Right Triangles The Chef is given a list of N triangles. Each triangle is identfied by ...

  7. POJ 3111 K Best(最大化平均值)

    题目链接:click here~~ [题目大意]有n个物品的重量和价值各自是Wi和Vi.从中选出K个物品使得单位重量的价值最大,输出物品的编号 [解题思路]:最大化平均值的经典.參见click her ...

  8. SQLite for C#

    slqlite是个轻量级的数据库,是目前较为流行的小型数据库,适用于各个系统..NET自然也是支持的 1.添加2个引用System.Data.SQLite.Linq,System.Data.SQLit ...

  9. JQuery 操作input

    获取选中的值 获取一组radio被选中项的值 var item = $('input[@name=items][@checked]').val(); 获取select被选中项的文本 var item ...

  10. css引入讲解及media

    引用Css的几种方式: 一.@import <style type="text/css" media="screen"> @import url(& ...