【题目链接】:http://codeforces.com/problemset/problem/777/E

【题意】



让你摆汉诺塔片;

要求在上面的片的外圈大于在下面的片的内圈,且小于下面的片的外圈;

给你n个片;

每个片有属性->外圈半径,内圈半径,高度;

然后让你选择其中的一些片;

使得它们叠起来高度最高;

【题解】



对于外圈半径相同的。

我们知道它们肯定是能够叠在一起的;

且我们可以把这些外圈相同的泛化成一个片;

这个片的外圈半径和原来的一样,内圈半径是这些外圈半径相同的片的内圈半径中最小的那个->即把内圈半径最小的那个放在最上面;->这样就能够最大限度地让上面的片能够多放一点了,且显然是正确的。

然后这个泛化出来的片的高度就是所有这个外圈半径的片的高度的和;

泛化完毕以后;

我们就得到了n个新的,外圈半径全都不同的片;

接下来我们把这些片按照外圈半径从大到小排序;

然后就能做一个类似最长不下降子序列的DP了

即设f[i]为以第i个片作为最上面那个片的最大高度;

f[i]=max(f[j])+h[i],这里j< i且j的内圈半径< r的外圈半径;

这里我们可以写个线段树来优化;

即在边做DP的时候,边维护内圈半径为r[i]的片的f[i]值;

这里的线段树,线段表示的就是内圈半径;值就是f[i]的值;

所以在查的时候query(1..i的外圈半径-1,1,n,1);

更新的时候同理;

写个离散化就行啦



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100; struct abc
{
LL a, b, h;
}; int n,totn;
abc a[N],b[N];
LL c[N], ma[N << 2],f[N],ans; bool cmp1(abc a, abc b)
{
return a.b > b.b;
} void up_data(int pos, LL val, int l, int r, int rt)
{
if (l == r)
{
ma[rt] = max(ma[rt], val);
return;
}
int m = (l + r) >> 1;
if (pos <= m)
up_data(pos, val, lson);
else
up_data(pos, val, rson);
ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);
} LL query(int L, int R, int l, int r, int rt)
{
if (L > R) return 0;
if (L <= l && r <= R)
return ma[rt];
int m = (l + r) >> 1;
LL temp1 = 0, temp2 = 0;
if (L <= m)
temp1 = query(L, R, lson);
if (R > m)
temp2 = query(L, R, rson);
return max(temp1, temp2);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
rel(a[i].a), rel(a[i].b), rel(a[i].h);
sort(a + 1, a + 1 + n, cmp1);
rep1(i, 1, n){
int j = i;
LL mi = a[i].a,height = a[i].h;
while (j + 1 <= n && a[j + 1].b == a[i].b) j++,mi = min(mi,a[j].a),height+=a[j].h;
b[++totn].b = a[i].b, b[totn].a = mi, b[totn].h = height;
c[totn] = mi;
i = j;
}
sort(c + 1, c + 1 + totn);
n = totn;
f[1] = b[1].h;
up_data(lower_bound(c + 1, c + 1 + n, b[1].a) - c,f[1], 1, n, 1);
rep1(i, 2, n)
{
int idx = upper_bound(c + 1, c + 1 + n, b[i].b - 1) - c -1;
LL bef = query(1, upper_bound(c + 1, c + 1 + n, b[i].b - 1) - c-1, 1, n, 1);
f[i] = max(f[i], bef + b[i].h);
idx = lower_bound(c + 1, c + 1 + n, b[i].a) - c;
up_data(lower_bound(c + 1, c + 1 + n, b[i].a) - c, f[i], 1, n, 1);
}
ans = f[1];
rep1(i, 2, n)
ans = max(ans, f[i]);
printf("%lld\n", ans);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 777E】Hanoi Factory的更多相关文章

  1. Codeforces 777E:Hanoi Factory(贪心)

    Of course you have heard the famous task about Hanoi Towers, but did you know that there is a specia ...

  2. Codeforces 777E:Hanoi Factory(贪心+栈)

    http://codeforces.com/problemset/problem/777/E 题意:给出n个环状圆柱,每个圆环有一个内半径a,外半径b,和高度h,只有外半径bj <= bi并且b ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. 洛谷P1390 公约数的和 [2017年6月计划 数论12]

    P1390 公约数的和 题目描述 有一天,TIBBAR和LXL比赛谁先算出1~N这N个数中每任意两个不同的数的最大公约数的和.LXL还在敲一个复杂而冗长的程序,争取能在100s内出解.而TIBBAR则 ...

  2. 【模板】矩阵快速幂 洛谷P2233 [HNOI2002]公交车路线

    P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...

  3. Centos系统Python环境搭建和项目部署

    目录 一.Python 1. 源安装 Python3 2. SCL安装 Python3 3. 虚拟环境venv 4. 安装Flask 5. 安装gunicorn 二.安装Nginx 1. 安装Ngin ...

  4. js实现自由落体

    实现自由落体运动需要理解的几个简单属性: clientHeight:浏览器客户端整体高度 offsetHeight:对象(比如div)的高度 offsetTop:对象离客户端最顶端的距离 <!d ...

  5. OpenLayers添加地图标记

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  6. 几种支持REST的Java框架

    目前宣称支持REST的Java框架包括以下这些: Restlet(http://www.restlet.org/) Cetia4(https://cetia4.dev.java.net/) Apach ...

  7. BZOJ2770: YY的Treap

    原本看标题还以为是treap的题,但是实际上是线段树. 求两点的LCA相当于求区间priority最小值的位置. 然后就可以离线先离散化然后建树做了. 记录的minpos是线段树上叶子结点的节点编号. ...

  8. database homework1

    mysql> select * from teacher_info; +----+------+-----+--------+---------+ | id | name | age | sal ...

  9. oracle审计实施

    1.语句审计 Audit session;  Audit session By ; 与instance连接的每个会话生成一条审计记录.审计记录将在连接时期插入并且在断开连接时期进行更新. 保留有关会话 ...

  10. Kubernetes1.4即将发布

    (一)发布历史 Kubernetes 1.0 - 2015年7月发布 Kubernetes 1.1 - 2015年11月发布 Kubernetes 1.2 - 2016年3月发布 Kubernetes ...