把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max,每次转移的时候直接从树状数组上查询前缀max即可,然后把更新出来的f[i]update进树状数组

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005;
int n,t[N],f[N],ans;
struct qwe
{
int l,r;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.r<b.r;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void update(int x,int v)
{
for(int i=x;i<=n;i+=(i&(-i)))
t[i]=max(t[i],v);
}
int ques(int x)
{
int r=0;
for(int i=x;i;i-=(i&(-i)))
r=max(r,t[i]);
return r;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i].l=read(),a[i].r=a[i].l+read()-1;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
int l=1,r=i-1,w=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid].r<a[i].l)
l=mid+1,w=mid;
else
r=mid-1;
}
f[i]=ques(w)+1;
update(i,f[i]);
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}

bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】的更多相关文章

  1. BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )

    先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...

  2. 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

    1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 255  S ...

  3. 【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. ...

  4. bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  5. [Usaco2006 Open]County Fair Events 参加节日庆祝

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  6. 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...

  7. bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】

    最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...

  8. 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套主席树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1901 首先还是吐槽时间,我在zoj交无限tle啊!!!!!!!!我一直以为是程序错了啊啊啊啊啊啊. ...

  9. BZOJ.4553.[HEOI2016&TJOI2016]序列(DP 树状数组套线段树/二维线段树(MLE) 动态开点)

    题目链接:BZOJ 洛谷 \(O(n^2)\)DP很好写,对于当前的i从之前满足条件的j中选一个最大值,\(dp[i]=d[j]+1\) for(int j=1; j<i; ++j) if(a[ ...

随机推荐

  1. LaTex/Overleaf使用笔记

    1. 添加网页引用 @misc{ r1,   author = "Wikipedia",   title = "Binary decision diagram --- { ...

  2. HDU 1800 hash 找出现最多次数的字符串的次数

    乘法hash: 这类hash函数利用了乘法的不相关性 int Hash(char *str){    int seed = 131 , value=0;    while(*str != '\0'){ ...

  3. Spring3.2+mybatis3.2+Struts2.3整合配置文件大全

    0.配置文件目录 1.Spring配置 applicationContext-dao.xml <?xml version="1.0" encoding="UTF-8 ...

  4. hdu - 3549 Flow Problem (最大流模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...

  5. UVA 11400_ Lighting System Design

    题意: 给定一系列灯泡的额定功率,电源价钱,一个灯泡的价格以及系统所需该种灯泡的数量.已知流过灯泡的电流相等,所以为省钱可以将电压小的灯泡换成电压大的灯泡,但是不能换成电压更小的灯泡,问最少要花多少钱 ...

  6. bzoj2212 Tree Rotations

    被BZOJ坑了一下午,原以为是我程序有问题一直WA,结果是我数组小了...为啥不给我RE!!! 线段树合并,对于逆序对而言,只能通过交换左右子树来达到,那么我们就可以想到对于一个结点而言,我们当然要取 ...

  7. ACM组队安排-——杭电校赛(递推)

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...

  8. USB2.0的最高传输速率

    USB2.0除了拥有USB1.1中规定的1.5Mbps和12Mbps两个传输模式以外,还增加了480Mbps高速数据传输模式(注:第二版USB2.0的传输速率将达800Mbps,最高理想值1600Mb ...

  9. 深入理解windows系统内的GMT和时区

    http://www.itshanghai.net/technology/wdzl_windowsxp/   UTC(Universal Time Coordinated)是通用协调时,这两者几乎是一 ...

  10. java IO流之三 使用缓冲流来读写文件

    原文:http://blog.csdn.net/haluoluo211/article/details/52183219 一.通过BufferedReader和BufferedWriter来读写文件 ...