【题意】

顺序经过k个点,求获得的最大权值和。

【思路】

设f[i]表示到第i个点,则有转移式:

f[i]=min{ f[j]+w[i] } x[j]<=x[i],y[j]<=y[i]

满足的条件是一个二维偏序,可以将x排序后用BIT维护y区间上的最大值。

又因为y比较大,所以需要提前离散化y坐标。

【代码】

 #include<set>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define trav(u,i) for(int i=front[u];i;i=e[i].nxt)
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
using namespace std; typedef long long ll;
const int N = 5e5+; ll read() {
char c=getchar();
ll f=,x=;
while(!isdigit(c)) {
if(c=='-') f=-; c=getchar();
}
while(isdigit(c))
x=x*+c-'',c=getchar();
return x*f;
} ll C[N],tot;
void upd(int x,ll v)
{
for(;x<=tot;x+=x&-x)
C[x]=max(C[x],v);
}
ll query(int x)
{
ll res=;
for(;x;x-=x&-x)
res=max(res,C[x]);
return res;
} struct Node {
int x,y,z;
bool operator < (const Node& rhs) const{
return x<rhs.x||(x==rhs.x&&y<rhs.y);
}
}ns[N]; int r,c,n;
int hash[N*]; int main()
{
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
r=read(),c=read(),n=read();
FOR(i,,n) {
ns[i].x=read(),ns[i].y=read(),ns[i].z=read();
hash[++tot]=ns[i].x,hash[++tot]=ns[i].y;
}
sort(hash+,hash+tot+);
tot=unique(hash+,hash+tot+)-hash-;
FOR(i,,n)
ns[i].y=lower_bound(hash+,hash+tot+,ns[i].y)-hash;
sort(ns+,ns+n+);
ll ans=;
FOR(i,,n) {
ll x=query(ns[i].y)+ns[i].z;
ans=max(ans,x);
upd(ns[i].y,x);
}
printf("%d",ans);
return ;
}

bzoj 1537 [POI2005]Aut- The Bus(DP+BIT)的更多相关文章

  1. 【BZOJ】1042: [HAOI2008]硬币购物(dp+容斥原理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1042 一开始写了个O(nv)的背包,果断tle... 看了题解,,好神..用了组合数学中的多重集合方 ...

  2. bzoj 1537: [POI2005]Aut- The Bus 线段树

    bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...

  3. 取数字(dp优化)

    取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...

  4. 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)

    洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...

  5. [Codeforces722E] Research Rover (dp+组合数学)

    [Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...

  6. BZOJ 1537: [POI2005]Aut- The Bus(dp + BIT)

    对y坐标离散化, 然后按x坐标排序, dp. 一个点(x, y), 设到达这个点接到的最多乘客数为t, 那么t可以用来更新y'>=y的所有点.用树状数组维护最大值. -------------- ...

  7. Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]

    1537: [POI2005]Aut- The Bus Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 387  Solved: 264[Submit][S ...

  8. 【BZOJ】1096: [ZJOI2007]仓库建设(dp+斜率优化)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1096 首先得到dp方程(我竟然自己都每推出了QAQ)$$d[i]=min\{d[j]+cost(j+ ...

  9. 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...

随机推荐

  1. 利用BBRSACryptor实现iOS端的RSA加解密

    背景 RSA这种非对称加密被广泛的运用于网络数据的传输,但其在iOS上很难直接实现,BBRSACryptor框架通过移植openssl实现了iOS端的RSA,本文将介绍如何使用BBRSACryptor ...

  2. 门面(Facade)模式(转)

    转载:http://www.cnblogs.com/skywang/articles/1375447.html 外部与一个子系统的通信必须通过一个统一的门面(Facade)对象进行,这就是门面模式. ...

  3. opencv求取RGB分量

    需要注意的是下面r,b,g的类型和顺序 须用IPL_DEPTH_8U类型创建图像且[0][1][2]分量分别是b,g,r. 另外多谢郑乾师兄帮我发现了IPL_DEPTH_8U问题 uchar r,b, ...

  4. vmware shared holder 虚拟机设置共享目录

    1, 安装 vm-tools http://askubuntu.com/questions/29284/how-do-i-mount-shared-folders-win7-host-in-ubunt ...

  5. Android权限安全(4)在什么时候检验权限?

    Android独有的Service等 : 通过PM的CheckPermission 其中 pm 是package manager services 非Android特有的Service等 : 映射为O ...

  6. BZOJ 3207 花神的嘲讽计划Ⅰ(函数式线段树)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3207 题意:给出一个数列,若干询问.每个询问查询[L,R]区间内是否存在某个长度为K的子 ...

  7. 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

    The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk ...

  8. 查看Linux服务器网络状态

    ifconfig 用来显示所有网络接口的详细情况的,如:ip地址,子网掩码等. ethx是以太网网卡的名称. 配置文件在/etc/sysconfig/network-scripts/ifcfg-eth ...

  9. Android系统服务-WindowManager

      WindowManager是Android中一个重要的服务 (Service ).WindowManager Service 是全局的,是唯一的.它将用户的操作,翻译成为指令,发送给呈现在界面上的 ...

  10. asp.net获取文件夹下的所有文件

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...