把长度转成右端点,按右端点排升序,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. 洛谷 P2335 SDOI 2005 毒瘤 位图(也补上注释了)

    #include<iostream> #include<cstdio> #include<queue> #include<cstring> using ...

  2. add favorite & 收藏夹

    add favorite // 收藏夹 function favorite (){ var ctrl = (navigator.userAgent.toLowerCase()).indexOf(&qu ...

  3. noip模拟赛 卖书

    分析:模拟题,只是有几个地方需要注意一下:第一个人必须支付5元,找零15元可以找一张10元一张5元,也可以找3张5元. #include <cstdio> #include <cst ...

  4. 安装K/3 Cloud过程中发现的两个新问题。

    卸载掉K/3 Cloud然后重装时出现下面的错误提示: 可能原因: 1.安装目录下的Setup.exe会检查操作系统版本.有些操作系统可能是被串改过注册信息,所以取不到版本信息(有些是因为盗版的原因) ...

  5. android开发里跳过的坑-android studio 错误 Could not find junit:junit:4.12

    在导入一个新项目时,出现错误Could not find junit:junit:4.12,网上大多是说缺少junit的jar包,但我查看了安装目录下是有jnuit包的,并且新建的项目都没有问题.几经 ...

  6. [NOIP2005] 提高组 洛谷P1053 篝火晚会

    题目描述 佳佳刚进高中,在军训的时候,由于佳佳吃苦耐劳,很快得到了教官的赏识,成为了“小教官”.在军训结束的那天晚上,佳佳被命令组织同学们进行篝火晚会.一共有n个同学,编号从1到n.一开始,同学们按照 ...

  7. 对付 MySQL 的死连接,Sleep的进程的来源探究[转]

    当前的连接数:mysql> show status like '%Threads_connected%';+-------------------+-------+| Variable_name ...

  8. 洛谷——P1454 圣诞夜的极光

    P1454 圣诞夜的极光 题目背景 圣诞夜系列~~ 题目描述 圣诞老人回到了北极圣诞区,已经快到12点了.也就是说极光表演要开始了.这里的极光不是极地特有的自然极光景象.而是圣诞老人主持的人造极光. ...

  9. SAP EP 设置Portal别名安全模式

    Securing the Portal Alias Cookie Context We recommend that you set the portal alias cookie to be del ...

  10. Servlet的文件上传

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/file-uploading.html: Servlet可以与HTML form标签一起使用允许用 ...