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的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  5. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  6. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  7. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  8. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

  9. bzoj千题计划250:bzoj3670: [Noi2014]动物园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...

随机推荐

  1. System 类的使用

    /*System 系统类 主要用于获取系统的属性数据.System类常用的方法: arraycopy(Object src, int srcPos, Object dest, int destPos, ...

  2. python实现树莓派开机自动发送IP到指定邮箱

    #!/usr/bin/python # -*- coding:UTF-8 -*- #测试发送邮件163邮箱发送到qq邮箱 import smtplib from email.mime.text imp ...

  3. Leetcode题库——23.合并k个排序链表

    @author: ZZQ @software: PyCharm @file: mergeKLists.py @time: 2018/10/12 19:55 说明:合并 k 个排序链表,返回合并后的排序 ...

  4. Sprint计划(未完成)

    1.需求预计:http://www.cnblogs.com/OuZeBo/p/4529320.html 2.功能设计: 3.Spring计划:

  5. 其实servlet就是一种mvc设计思想的一种实现

    看图,不说话

  6. SpringMVC运行原理浅析

    SpringMVC是主流的J2EEWEB层框架,SpringMVC是Sping家族中一个重要的产品.下面给出SpringMVC的运行原理.springmvc和spring无需通过中间层进行整合,spr ...

  7. WinForm中DataGridView的快速查找及将指定行显示到第一行

    /// <summary> /// 快速在已绑定的列表查询车辆 /// </summary> /// <param name="sender"> ...

  8. PHP-时间函数

    1.时间格式化函数date(format,timestamp) format 时间格式 timestamp 时间戳 下面列出了一些常用于日期的字符: d - 表示月里的某天(01-31) m - 表示 ...

  9. Linux服务器学习(二)

    昨天简单了解了linux的基础命令,今天学习linux搭建环境(安装文件,配置文件)及权限操作. 一.搭建lnmp环境 lnmp指Linux+Nginx+Mysql+PHP Ubuntu安装文件命令为 ...

  10. 2013南京网赛1003 hdu 4750 Count The Pairs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:给出一个无向图,f(a,b)表示从点a到点b的所有路径中的每条路径的最长边中的最小值,给出 ...