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[ ...
随机推荐
- 如何获取多核、多cpu系统中指定cpu的序列号
如何获取多核.多cpu系统中指定cpu的序列号作者:SkyJacker(转贴请保持完整并注明作者和出处)http://www.cnpack.orgCnPack IV QQ Group: 130970 ...
- 6、JPA_映射单向多对一的关联关系(n的一方有1的引用,1的一方没有n的集合属性)
单向多对一的关联关系 具体体现:n的一方有1的引用,1的一方没有n的集合属性 举个例子:订单Order对顾客Customer是一个单向多对一的关联关系.Order是n的一方,有对Customer的引用 ...
- mysql shell
mysql 查询10分钟以内的数据:select *from t_agent where int_last_login>=CURRENT_TIMESTAMP - INTERVAL 10 MINU ...
- laravel Restful
参考:http://www.cnblogs.com/youxin/p/3967274.html http://scotch.io/tutorials/simple-laravel-crud-with- ...
- node解析查询字符串
var http=require("http"); var url=require("url"); var pages=[ {id:"1", ...
- Mybatis中配置Mapper的方法
在这篇文章中我主要想讲一下Mybatis配置文件中mappers元素的配置.关于基础部分的内容可以参考http://haohaoxuexi.iteye.com/blog/1333271. 我们知道在M ...
- Cookie的具体使用之来存储对象
1.创建一个新的cookie,并赋值. HttpCookie cookie; cookie=new HttpCookie("user"); cookie.D ...
- BZOJ 2299 向量
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2299 题意:给出一对数a,b,任意使用(a,b), (a,-b), (-a,b), (- ...
- [HDOJ1811]Rank of Tetris(并查集、拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1811 求一堆数据的拓扑序. 处理:x>y就是x到y一条边,x<y就是y到x一条边.关键问题 ...
- subsets-ii(需要思考,包括了子数组的求法)
还是有一定难度的. 基本方法,就是用队列,然后不断累加新的数.这是为了不重复而量身定制的. 如果运行重复,是有更简单清晰的方法,就是每次增加考虑一个数字,然后加到本来每一个结果的后面.如下: publ ...