bzoj 1537 [POI2005]Aut- The Bus(DP+BIT)
【题意】
顺序经过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)的更多相关文章
- 【BZOJ】1042: [HAOI2008]硬币购物(dp+容斥原理)
http://www.lydsy.com/JudgeOnline/problem.php?id=1042 一开始写了个O(nv)的背包,果断tle... 看了题解,,好神..用了组合数学中的多重集合方 ...
- 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][ ...
- 取数字(dp优化)
取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...
- 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)
洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...
- [Codeforces722E] Research Rover (dp+组合数学)
[Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...
- BZOJ 1537: [POI2005]Aut- The Bus(dp + BIT)
对y坐标离散化, 然后按x坐标排序, dp. 一个点(x, y), 设到达这个点接到的最多乘客数为t, 那么t可以用来更新y'>=y的所有点.用树状数组维护最大值. -------------- ...
- Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
1537: [POI2005]Aut- The Bus Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 387 Solved: 264[Submit][S ...
- 【BZOJ】1096: [ZJOI2007]仓库建设(dp+斜率优化)
http://www.lydsy.com/JudgeOnline/problem.php?id=1096 首先得到dp方程(我竟然自己都每推出了QAQ)$$d[i]=min\{d[j]+cost(j+ ...
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
随机推荐
- 遍历并remove HashMap中的元素时,遇到ConcurrentModificationException
遍历并remove HashMap中的元素时,遇到ConcurrentModificationException for (Map.Entry<ImageView, UserConcise> ...
- PCA understanding
PCA understanding 我们希望获取玩具的位置,事实上我们只需要知道玩具在x轴的位置就可以了(但现实不知道).我们利用三个坐标轴,获取了2*3维度的数据,现实中我们如何通过分析六维度数据来 ...
- 浅谈PHP自动化代码审计技术
原文出处: exploit 欢迎分享原创到伯乐头条 0×00 由于博客实在没什么可以更新的了,我就把目前做的事情总结一下,当做一篇博客,主要是谈一谈项目中所运用的一些技术.目前市面上有不少PHP的 ...
- How to learn linux device driver
To learn device driver development, like any other new knowledge, the bestapproach for me is to lear ...
- js、javascript正则表达式验证身份证号码
function isCardNo(card) { // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X var reg = /(^\d{1 ...
- jpa懒加载异常
1.项目背景概述 事情是这样子的,使用了spring data jpa的项目jeesite jeesite的实体中使用了懒加载模式. 并且一个实体类中还不止一个属性设置了懒加载模式. 项目本身已经存在 ...
- NDK(12)Jni常用函数
参考官方文档 http://docs.oracle.com/javase/7/docs/technotes/guides/jni/ http://docs.oracle.com/javase/7/do ...
- Image.FrameDimensionsList 属性备注
Image.FrameDimensionsList 属性 .NET Framework 2.0 获取 GUID 的数组,这些 GUID 表示此 Image 中帧的维数. 命名空间:System.D ...
- struts1,struts2,springMVC终极对比
最近做项目用到了struts2,之前一直是用struts1和springMVC.感觉到了struts2从很大程度上和这两个还是有很大区别的,所以今天搜集了些资料,给他们做一下对比. Struts1官方 ...
- Android开发之assets文件夹中资源的获取
assets中的文件都是保持原始的文件格式,需要使用AssetManager以字节流的形式读取出来 步骤: 1. 先在Activity里面调用getAssets() 来获取AssetManager引用 ...