bzoj千题计划148:bzoj1537: [POI2005]Aut- The Bus
http://www.lydsy.com/JudgeOnline/problem.php?id=1537
朴素的转移:dp[i][j]=max(dp[i][j-1],dp[i-1][j])+p[i][j]
树状数组优化
按x排序,离散化y
枚举,排序保证x,树状数组查询y
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 100001 #define lowbit(x) x&-x int c[N]; struct node
{
int x,y,p;
}e[N]; int tot,has[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void change(int x,int y)
{
while(x<=tot)
{
c[x]=max(c[x],y);
x+=lowbit(x);
}
} int query(int x)
{
int mx=;
while(x)
{
mx=max(mx,c[x]);
x-=lowbit(x);
}
return mx;
} bool cmp(node p,node q)
{
if(p.y!=q.y) return p.y<q.y;
return p.x<q.x;
} int main()
{
int n,m,k;
read(n); read(m); read(k);
for(int i=;i<=k;++i)
{
read(e[i].x);
read(e[i].y);
read(e[i].p);
has[i]=e[i].x;
}
sort(has+,has+k+);
tot=unique(has+,has+k+)-has-;
sort(e+,e+k+,cmp);
int tmp,pos; int ans=;
for(int i=;i<=k;++i)
{
pos=lower_bound(has+,has+tot+,e[i].x)-has;
tmp=e[i].p+query(pos);
ans=max(ans,tmp);
change(pos,tmp);
}
cout<<ans;
}
bzoj千题计划148:bzoj1537: [POI2005]Aut- The Bus的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- C++自学笔记(3)
类和对象 对象 具体指代一个事物 类 为了便于管理,将信息抽象. 目的不同,抽象的信息也不同(选择性暴露),也就是封装. 通过访问限定符,选择想要暴露和隐藏的信息. 对象实例化 计算机根据一个类的设计 ...
- Maven3 用Maven创建第一个web项目(2)servlet演示
上一章用Maven新建了web项目成功后,本文演示在此基础上应用servlet. 1.首先修改pom.xml文件,添加servlet依赖 <project xmlns="http:// ...
- 第九周(11.11-11.17)----Beta版本发布140字评论
1.新蜂组: 俄罗斯方块:项目有良好的用户界面,在原版的基础上可以对用户分数进行排序,增加了显示下一个方块的功能.是个很有趣的小游戏. 2.天天向上组: 连连看:完成了基本功能,增加了消除时和鼠标点击 ...
- 利用css制作带边框的小三角
标签(空格分隔):css 在项目中会使用到的小实例,目前知道的有两种方法来实现 设置元素的宽和高,利用rotate实现,比较简单的一种 div{ width: 10px; height: 10px; ...
- Delphi 使用TAdoQuery执行存储过程的样例
procedure TCustomerForm.FindCustomerInfo;var strSql:string;begin // BL_HV_FindCustomerInfo 存储过程的名称 ...
- PHP时间格式化参数表笔记
date_create_from_format() 函数返回一个根据指定格式进行格式化的新的 DateTime 对象.通常需要配合date_format()函数使用 语法: date_create_f ...
- [转帖]脑残式网络编程入门(二):我们在读写Socket时,究竟在读写什么?
脑残式网络编程入门(二):我们在读写Socket时,究竟在读写什么? http://www.52im.net/thread-1732-1-1.html 1.引言 本文接上篇<脑残式网 ...
- crosses initialization of “XXX” 的问题
在switch-case中定义了变量,用g++编译的时候报错crosses initialization of “XXX” ,在网上一查,说是gcc要求变量的定义不能位于goto之后 将变量定义放在s ...
- JVM 规范
http://files.cnblogs.com/files/dragonsuc/jls8.pdf 或者官网:http://files.cnblogs.com/files/dragonsuc/jls8 ...
- UVA10054_The Necklace
很简单,求欧拉回路.并且输出. 只重点说一下要用栈来控制输出. 为啥,如图: 如果不用栈,那么1->2->3->1就回来了,接着又输出4->5,发现这根本连接不上去,所以如果用 ...